2009-05-27 37 views
1

我只是想首先使用自我跟蹤POCO方法做一些廣泛的模型。然而,我並沒有按照我的意願去工作。我們開個博客吧。每個博客都有一組條目,每個條目都有一組評論。不幸的是,下面的模型不適合我。 alt text http://blog.zoolutions.se/issue.pngEF4 - POCO問題

的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: Schema specified is not valid. Errors: 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.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+Entry'.

任何線索?我無法圍繞該錯誤消息打包我的頭......

回答

4

在Beta1中,CLR類到EDM類型的映射有點不可原諒。

聽起來好像這裏的問題是發現多個'Entry'類與所需的'Entry'實體不匹配。我們應該忽略這些,但在Beta1中我們不這樣做,你會得到一個例外。

我們已經爲此進行了下一次測試,因此EF繼續尋找匹配的類,並且在您的情況下會找到您的Entry類,並且一切都會好的。

在Beta2發佈之前,您可能需要將Entry類的名稱更改爲更獨特的東西。

希望這有助於在實體框架團隊

亞歷

項目經理。

+0

感謝Alex,我將它改爲了BlogEntry,但是我發現有一些我發現我已經將Blog的Id字段設置爲bool以及:)我遇到了一些其他問題,但它們更容易處理。 – mhenrixon 2009-05-28 09:42:40

1

無法在Alex James的回覆下添加此帖子。

EF4仍然有一個bug,類似的事情已經在EF 4 Beta 2中

我曾經遇到過一個bug在同類local名稱類存儲包含實體組件​​中的固定由微軟,但屬於到不同的EF4 edmx模型文件(例如:當實體存在於GeographyConfigurationModel.edmx和CustomerServiceModel.edmx中時)。這兩個Country類在每個模型中包含不同的屬性集,並且每個模型都位於單獨的項目文件夾中,指定了entity namespace模型屬性(並立即忽略)。