2017-03-01 44 views
0

我使用實體框架代碼首先的創建數據庫 學習通過天青手機應用服務CS0246 C#中的類型或命名空間名稱「ForeignKeyAttribute」找不到(是否缺少using指令或程序集引用?)

但我得到了一個錯誤,它看起來像

enter image description here

CS0246 C# The type or namespace name 'ForeignKeyAttribute' 
could not be found (are you missing a using directive or an assembly reference?) 

而且我心中已經È已經使用System.ComponentModel.DataAnnotations.Schema; 但它似乎不工作。

我該如何解決這個問題?

============================================== =======

最後,我解決它指的是這個! Why can't I reference System.ComponentModel.DataAnnotations?

+0

EF哪個版本的,你定位? – mlapaglia

+0

EntityFramework.dll,Runtime版本v4.0.30319:「( –

+0

嗯,什麼版本的.NET?http://stackoverflow.com/questions/20705040/entity-framework-modeling-with-net4-data-annotations-issue – mlapaglia

回答

1

System.ComponentModel.DataAnnotations是ForeignKey以及Required的命名空間。

System.ComponentModel.DataAnnotations.Schema更爲具體。例如,如果您想將字段映射到特定的列名稱或實體到表名稱。

相關問題