EF 5 AddOrUpdate Duplicates data

前端 未结 1 1675
梦谈多话
梦谈多话 2021-01-06 05:44

This is the code in the Seed method:

var city = new City { Name = \"A\" };

var nh = new List
{
    new Neigh { City = city, Name = \"N1\" },
           


        
相关标签:
1条回答
  • 2021-01-06 06:17

    You must start the script by checking whether the city already exists:

    var city = context.Cities.FirstOrDefault(c => c.Name == "A") 
                                         ?? new City { Name = "A" };
    
    0 讨论(0)
提交回复
热议问题