Good afternoon.
Made similar to the example of Many to many Generic update method EF 6
But in my case, the values from the collection property are re-created in the "DB".
public void Update(T updateItem) { using (var databaseContext = new TelesystemContext()) { T foundDal = databaseContext.Set<T>().Find(updateItem.Id); var entry = databaseContext.Entry(foundDal); entry.CurrentValues.SetValues(updateItem); var collection = entry.Collection("Permissions"); collection.Load(); collection.CurrentValue = typeof(T).GetProperty("Permissions").GetValue(updateItem); databaseContext.SaveChanges(); } }
Those. Permissions
each time you save an updateItem
object are created anew, and should simply be added to the table — a bunch of many-to-many.
databaseContext.Entry(updateItem).State = EntityState.Modified;
- Pavel Mayorov