开发者

Web forms EF4 CodeFirst CTP5 KeyAttribute not found

开发者 https://www.devze.com 2023-03-04 23:28 出处:网络
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 sayin

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.Compon开发者_如何转开发entModel.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!


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号