.NET4的实体框架建模,数据注释问题 [英] Entity Framework modeling with .NET4, Data Annotations issue

查看:89
本文介绍了.NET4的实体框架建模,数据注释问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的网站上使用实体框架。我遵循了教程,Visual Studio(2010)并没有抱怨。但是,当我添加一个ForeignKey数据批注时,当我在网站上运行时出现错误,提示命名空间不存在。
CS0246:找不到类型或名称空间名称 ForeignKey(您是否缺少using指令或程序集引用?)

I am trying to use Entity Framework on my web site. I followed tutorials and Visual Studio (2010) does not complain. 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. CS0246: The type or namespace name 'ForeignKey' could not be found (are you missing a using directive or an assembly reference?)

进行一些搜索后,看来.NET 4中不存在ForeignKey数据注释。

After doing some searching, it appears that the ForeignKey data annotation does not exist in .NET 4.

如果是这样,是否可以在.NET 4中的模型上添加外键?

If that is the case, is there a way to add at foreign key to the model in .NET 4?

推荐答案

正确的System.ComponentModel.DataAnnotations。架构是.NET 4.5的一部分。

Correct, System.ComponentModel.DataAnnotations.Schema is part of .NET 4.5.

您改为看了Fluent API吗?

Have you instead looked at the Fluent API?

这是一个视频专门针对VS 2010。 http://msdn.microsoft.com/en-ca/data/gg194009.aspx

Here's a video for VS 2010 specifically. http://msdn.microsoft.com/en-ca/data/gg194009.aspx

这篇关于.NET4的实体框架建模,数据注释问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆