public void Update(Order order) { using (var db = new OrderDB()) { db.Order.Attach(order); db.Entry(order).State = EntityState.Modified; List <OrderDetails> odl = GetAllOrderDetails(); foreach (OrderDetails details in order.orderDetails) { bool exist = false; foreach (OrderDetails detailed in odl) { if (detailed.ID == details.ID) { exist = true; break; } } db.Entry(details).State = EntityState.Modified; if (!exist) { db.OrderDetail.Add(details); } } //order.orderDetails.ForEach( // item => db.Entry(item).State = EntityState.Modified); db.SaveChanges(); } }
public void Update(Order order) { using (var db = new OrderDB()) { db.Order.Attach(order); db.Entry(order).State = EntityState.Modified; order.Details.ForEach( item => db.Entry(item).State = EntityState.Modified); db.SaveChanges(); } }