【问题标题】:EF4 - POCO ProblemEF4 - POCO 问题
【发布时间】:2009-05-27 19:55:34
【问题描述】:

我只是想先使用自我跟踪 POCO 方法做一些广泛的模型。但是,我没有让它按我的意愿工作。让我们来个博客。每个博客都有一组条目,每个条目都有一组评论。不幸的是,以下模型对我不起作用。 alt text http://blog.zoolutions.se/issue.png

POCO 类实现如下所示:

public class Blog
{
    public bool Id { get; private set; }
    public string Title { get; set; }
    public bool AllowComments { get; set; }
    public User User { get; set; }
    public IList<Entry> Entries { get; set; }
}

public abstract class Post
{
    public virtual int Id { get; set; }
    public virtual string Header { get; set; }
    public virtual string Text { get; set; }
    public virtual DateTime CreatedAt { get; set; }
    public virtual int UserId { get; set; }
}

public class Entry : Post
{
    public Blog Blog { get; set; }
    public IList<Comment> Comments { get; set; }        
}

public class Comment : Post
{
    public Entry Entry { get; set; }
}

这给了我一个非常奇怪的错误:

System.Data.MetadataException:架构 指定无效。错误: CLR 类型到 EDM 类型的映射是 模棱两可,因为有多种 CLR 类型 匹配 EDM 类型“条目”。之前 发现 CLR 类型 'Entry',新发现 CLR 类型 'System.Collections.Generic.Dictionary2+Entry'. The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Entry'. Previously found CLR type 'Entry', newly found CLR type 'System.Runtime.CompilerServices.ConditionalWeakTable2+Entry'。

有什么线索吗?我无法理解该错误消息...

【问题讨论】:

    标签: entity-framework


    【解决方案1】:

    在 Beta1 中,CLR 类到 EDM 类型的映射有些难以接受。

    听起来好像这里的问题是发现了多个与所需的“Entry”实体不匹配的“Entry”类。我们应该忽略这些,但在 Beta1 中我们不会,而且您会遇到异常。

    我们已经为下一个测试版进行了这项工作,因此 EF 会继续寻找匹配的类,在您的情况下会找到您的 Entry 类,一切都会好起来的。

    在 Beta2 发布之前,您可能需要将 Entry 类的名称更改为更独特的名称。

    希望对你有帮助

    亚历克斯

    Entity Framework 团队的项目经理。

    【讨论】:

    • 感谢 Alex,我将其更改为 BlogEntry,但有些我发现我也将 Blog 的 Id 字段设置为 bool :) 我遇到了其他一些问题,但它们更容易处理。
    • 哦,继续努力,Alex,我真的很喜欢你使用 EF4!
    【解决方案2】:

    无法在 Alex James 的回复下添加此帖子。

    EF4 仍有一个错误,微软已经在 EF 4 Beta 2 中修复了类似的问题。

    当具有相似 local 名称的类存储在包含实体的程序集中但属于不同的 EF4 edmx 模型文件时,我遇到了一个错误(例如:当两个 GeographyConfigurationModel.edmx 中存在 Country 实体时,和 CustomerServiceModel.edmx)。两个Country 类在每个模型中包含不同的属性集,并且每个模型都位于单独的项目文件夹中,指定了entity namespace 模型属性(并立即忽略)。

    【讨论】:

      猜你喜欢
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-05
      • 2011-01-03
      相关资源
      最近更新 更多