EF 5 AddOrUpdate Duplicates Data
This is the code in the Seed method:
var city = new City { Name = "A" }; var nh = new List<Neigh> { new Neigh { City = city, Name = "N1" }, new Neigh { City = city, Name = "N2" }, new Neigh { City = city, Name = "N3" }, //new Neigh { City = city, Name = "N4" }, }; context.Neighs.AddOrUpdate( p => p.Name, nh.ToArray() ); After starting the update database, everything works as expected. I can run it several times without problems. However, if at some point I uncomment the fourth quarter and again earn the update database, I get two records with the city “A”, and N4 points to this city, and the rest points to the original city.
How to prevent duplicate city insertion if the list is updated?