【问题标题】:Web forms EF4 CodeFirst CTP5 KeyAttribute not found未找到 Web 表单 EF4 CodeFirst CTP5 KeyAttribute
【发布时间】: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


【解决方案1】:

我没有先将其发布为答案,因为我不确定问题是否不在其他地方。您必须将System.ComponentModel.DataAnnotations.dll 添加到项目引用中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-02
    • 2011-07-15
    • 2023-04-02
    • 2011-06-16
    • 2013-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多