【发布时间】:2011-05-12 23:06:54
【问题描述】:
我在带有 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] 属性。任何提示都非常感谢。谢谢!
【问题讨论】:
-
您必须将
System.ComponentModel.DataAnnotations.dll添加到项目引用中。顺便提一句。 CTP5 非常陈旧且过时。您应该升级到最终版本的 EF 4.1 RTW。 -
@Ladislav,太好了,正如你所说,它现在正在工作。非常感谢,也感谢关于 RTW 的提示。我想将您的评论标记为答案,但前提是您将其发布为答案而不是评论。
标签: entity-framework-4 webforms entity-framework-ctp5