2016-07-25 95 views
0

我想在我的EF Code First業務對象中實現Dev Express IResource中定義的接口。沒有定義密鑰。在實現具有Id的接口時定義此EntityType的密鑰

public class JResource : IResource , IXafEntityObject 
    { 
     [Key] 
     public int IdKey { get; set; } 
     [NotMapped] 
     public object Id => IdKey; // since IResource wants this. 
     // other properties 
    } 

當我運行我的應用程序來創建數據庫時,出現一個錯誤,我需要爲此EntityType定義鍵。

我認爲問題在於EF想把Id當作鑰匙,但是我做了Id NotMapped,因爲我希望它是一個Int,接口希望它是一個對象。

是否有解決方法?

回答

0

原來我對[Key]屬性使用了錯誤的引用。 正確的是

System.ComponentModel.DataAnnotations.KeyAttribute 
相關問題