2017-03-01 100 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更为具体。例如,如果您想将字段映射到特定的列名称或实体到表名称。

相关问题