Entity Framework Code First AddOrUpdate method insert Duplicate values

后端 未结 13 1196
清酒与你
清酒与你 2020-12-01 08:52

I have simple entity:

public class Hall
{
    [Key]
    public int Id {get; set;}

    public string Name [get; set;}
}

Then in the S

13条回答
  •  抹茶落季
    2020-12-01 09:31

    I used the ID field as Identity/Key and add attributes not to assign Ids by the server. This solved the problem for me.

    public class Hall
    {
        [Key]
        [Required]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int Id {get; set;}
    
        public string Name [get; set;}
     }
    

提交回复
热议问题