Search code examples
entity-framework-4webformsentity-framework-ctp5

Web forms EF4 CodeFirst CTP5 KeyAttribute not found


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!


Solution

  • 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.