Entity Framework Code First - Cannot insert duplicate key in object 'db'

前端 未结 4 914
感动是毒
感动是毒 2021-01-25 17:00

I\'m using the new EF code first to one project of mine, and i\'m getting a weird error, my mode is:

abstract class Member
{
   public virtual int MemberId;
  ..         


        
4条回答
  •  一整个雨季
    2021-01-25 17:19

    I just came across this. Like the marked answer states, TPC doesn't set the key to an identity. So you can use an annotation for it:

    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int ID { get; set; }
    

提交回复
热议问题