asp .net MVC应用程序无法识别[Key,Column(Order = 0)]属性

时间:2013-01-13 18:54:08

标签: asp.net-mvc entity-framework code-first

using System.ComponentModel.DataAnnotations;    

public class UserArmy
    {
        [Key, Column(Order = 1)]
        public Guid UserId { get; set; }
        [Key, Column(Order = 2)]
        public int UnitId { get; set; }
        public int Quantity { get; set; }
    }

这是我的模特课。我正在使用实体框架,Code First方法。 [Key]属性被识别但不是Column(Order = x)。

我错过了需要包含的内容吗?

谢谢:)

1 个答案:

答案 0 :(得分:4)

您必须添加以下命名空间:

using System.ComponentModel.DataAnnotations.Schema;

http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.schema.aspx