diff --git a/ConfectioneryDatabaseImplement/Shop.cs b/ConfectioneryDatabaseImplement/Shop.cs index 190e58d..bd87290 100644 --- a/ConfectioneryDatabaseImplement/Shop.cs +++ b/ConfectioneryDatabaseImplement/Shop.cs @@ -106,12 +106,16 @@ namespace ConfectioneryDatabaseImplement.Models } } var shop = context.Shops.First(x => x.Id == model.Id); - shop.ShopPastries.AddRange(model.Pastries.Select(x => new ShopPastry - { - Pastry = context.Pastries.First(y => y.Id == x.Key), - Count = x.Value.Item2, - }).Except(shopPastries ?? new())); - context.SaveChanges(); + foreach (var pc in model.Pastries) + { + context.PastryComponents.Add(new() + { + Pastry = context.Pastries.First(y => y.Id == pc.Key), + Count = pc.Value.Item2, + }); + context.SaveChanges(); + } + context.SaveChanges(); _cachedPastries = null; } }