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

前端 未结 4 1450
被撕碎了的回忆
被撕碎了的回忆 2021-01-25 16:46

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:09

    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; }
    

提交回复
热议问题