开发者

How can define multiple KEY in EntityFrameWorkClass C#

[Table("Table_UserImages")]
public class UserImage
{
     [Key, Column("UserID")]
     public Nullable<Guid> UserID { get; set; }
     [Key, Column("ImageID")]
     public Nullable<int> ImageID { get; set; }  
}

开发者_Go百科Both column are Primary key but model only accept one Key at a time,then how can i over come this? have any solution ? please share?


I believe you're describing a composite key, that is a key composed of two or more columns.

To describe this in EF, you need to also define the column ordering for the keys. Like this:

[Table("Table_UserImages")]
public class UserImage
{
    [Key, Column("UserID", Order=0)]
    public Guid? UserID { get; set; }
    [Key, Column("ImageID", Order=1)]
    public int? ImageID { get; set; }  
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜