entity-framework – 实体类型没有键定义的EF6
发布时间:2020-12-16 07:10:55 所属栏目:asp.Net 来源:网络整理
导读:这是我的代码,虽然我已经改进了关键属性,但仍然存在问题. public class Contacts{ [Key] public int ContactId { get; set; } public string Name { get; set; } public string Address { get; set; } public string City { get; set; } public string State
这是我的代码,虽然我已经改进了关键属性,但仍然存在问题.
public class Contacts { [Key] public int ContactId { get; set; } public string Name { get; set; } public string Address { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } [DataType(DataType.EmailAddress)] public string Email { get; set; } } 我得到的错误是:
解决方法
如果您使用的是EF Code First(未在问题中指定),则需要将ContactId属性名称更改为ContactsId以匹配ClassName Id的约定,以便为Contacts实体类型定义键.
请参阅MSDN Code First Conventions:http://msdn.microsoft.com/en-us/data/jj679962.aspx (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- ASP.NET程序员常用的85个工具
- 如何使用asp.net web.sitemap和菜单控件与bootstrap
- asp.net-mvc-routing – Web API路由和Web API帮助页面:如
- asp.net-mvc-5 – 更改消息“密码必须至少包含一个非字母或
- asp.net – 界面的好处是什么意味着某种实现?
- asp.net – 当我将’启用32位应用程序’更改为False时,为什
- Asp.Net,DropDownList,AutoPostBack和Google Chrome
- asp.net-mvc – 洋葱建筑 – 存储库与服务?
- ASP.NET Core 中间件基本用法
- asp.net – 如何使用转换语法更改web.config设置?
推荐文章
站长推荐
- asp.net – 在TableRowCollection上使用linq
- 从ASP.NET工作进程ID获取性能计数器实例名称(w3w
- asp.net – 通过Button控制Fire AsyncFileUpload
- 基于Azure IoT开发.NET物联网应用系列-全新的Azu
- asp.net-mvc – Mvc4绑定,缩小和AngularJS服务
- asp.net – 错误:找不到此项目类型所基于的应用
- asp.net – 是否可以强制WebControl呈现为而不是
- asp.net – 来自asp app的流媒体mime类型’appli
- ASP.NET页面上的多种语言(英语,法语)
- asp.net – 无法在动态创建的System.Web.UI.WebC
热点阅读