代码之家  ›  专栏  ›  技术社区  ›  mhenrixon

EF4-POCO问题

  •  1
  • mhenrixon  · 技术社区  · 15 年前

    我只是想先用自跟踪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类型“entry”。以前 找到clr类型“entry”,新找到 CLR类型 'System.Collections.Generic.Dictionary 2+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.ConditionalWeakTable 2 +条目。

    有什么线索吗?我不能把我的头绕在那个错误信息上…

    2 回复  |  直到 13 年前
        1
  •  4
  •   Alex James    15 年前

    在beta1中,clr类到edm类型的映射有些不可原谅。

    这里的问题似乎是发现多个“entry”类与所需的“entry”实体不匹配。我们应该忽略这些,但是在beta1中,我们没有,你会得到一个例外。

    我们已经为下一个测试版做了这个工作,所以英孚会继续寻找一个匹配的类,在你的情况下,会找到你的入门类,一切都会好的。

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

    希望这有帮助

    亚历克斯

    实体框架团队的项目经理。

        2
  •  1
  •   timmi4sa    13 年前

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

    EF4仍然有一个bug,类似的东西已经被微软在EF4测试版2中修复了。

    当类与 local 名称存储在包含实体的程序集中,但属于不同的EF4 edmx 模型文件(例如:何时 Country 实体同时存在于geographyconfigurationmodel.edmx和customerservicemodel.edmx中)。两个 国家 类在每个模型中包含不同的属性集,并且每个模型位于单独的项目文件夹中, entity namespace 指定了模型属性(并立即忽略)。