简体   繁体   English

.NET4的实体框架建模,数据注释问题

[英]Entity Framework modeling with .NET4, Data Annotations issue

I am trying to use Entity Framework on my web site. 我正在尝试在我的网站上使用实体框架。 I followed tutorials and Visual Studio (2010) does not complain. 我遵循了教程,Visual Studio(2010)并没有抱怨。 However, when I add a ForeignKey data annotation, I get an error when I run on the web site that the Namespace does not exist. 但是,当我添加一个ForeignKey数据批注时,当我在网站上运行时出现错误,提示命名空间不存在。 CS0246: The type or namespace name 'ForeignKey' could not be found (are you missing a using directive or an assembly reference?)

After doing some searching, it appears that the ForeignKey data annotation does not exist in .NET 4. 搜索后,看来.NET 4中不存在ForeignKey数据注释。

If that is the case, is there a way to add at foreign key to the model in .NET 4? 如果是这样,是否有办法在.NET 4中向模型添加外键?

Correct, System.ComponentModel.DataAnnotations.Schema is part of .NET 4.5. 正确,System.ComponentModel.DataAnnotations.Schema是.NET 4.5的一部分。

Have you instead looked at the Fluent API? 您是否看过Fluent API?

Here's a video for VS 2010 specifically. 这是专门针对VS 2010的视频。 http://msdn.microsoft.com/en-ca/data/gg194009.aspx http://msdn.microsoft.com/en-ca/data/gg194009.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM