1
我在使用EF4和CTP5的Web窗體(而不是MVC)中使用代碼優先,並嘗試裝飾具有[Key]屬性的屬性時,它不顯示在智能感知和編譯錯誤說KeyAttribute沒有找到。這裏是我的代碼:Web窗體EF4 CodeFirst CTP5 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。 – 2011-05-11 19:32:12
@拉迪斯拉夫,很棒,就像你說的那樣,現在正在工作。非常感謝,也感謝RTW的提示。我想將您的評論標記爲答案,但只有當您將其發佈爲答案而不是評論時纔可以。 – Nestor 2011-05-12 14:55:57