Web 表单 EF4 CodeFirst CTP5 KeyAttribute 未找到
我在带有 EF4 和 CTP5 的 Web 表单(不是 MVC)中使用代码优先,当尝试使用 [Key] 属性装饰属性时,它不会显示在智能感知中,并会出现编译错误,提示 KeyAttribute 不是成立。这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace ERP.Models
{
public class CustomerAddress
{
[Key]
public int AddressID { get; set; }
public int CustomerID { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public int CityID { get; set; }
public int SateID { get; set; }
}
}
我已经包含了 DataAnnotations 库,一切看起来都不错,但是找不到 [Key] 属性。任何提示都将受到高度赞赏。谢谢!
I'm using code-first in Web Forms (not MVC) with EF4 and CTP5, and when trying to decorate a property with the [Key] attribute, it doesn't show up in the intellisense and get compilation error saying KeyAttribute was not found. Here is my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace ERP.Models
{
public class CustomerAddress
{
[Key]
public int AddressID { get; set; }
public int CustomerID { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public int CityID { get; set; }
public int SateID { get; set; }
}
}
I have included the DataAnnotations library, all looks ok, but the [Key] attribute is not found. Any hint is highly appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有首先将其作为答案发布,因为我不确定问题是否出在其他地方。您必须将 System.ComponentModel.DataAnnotations.dll 添加到项目引用中。
I didn't post it as answer first because I wasn't sure if the problem is not elsewhere. You must add
System.ComponentModel.DataAnnotations.dll
to project references.