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

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?

1 Answer 1

4

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; }  
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.