public void AddOrder(Order order) { using (var db = new OrderDB()) { db.tb_Order.Add(order); db.SaveChanges(); } }
public void Update(Order order) { using (var db = new OrderDB()) { db.tb_Order.Attach(order); db.Entry(order).State = EntityState.Modified; order.Items.ForEach(item => db.Entry(item).State = EntityState.Modified); db.SaveChanges(); } }
public void DeleteByID(String id) { using (var db = new OrderDB()) { var order = db.tb_Order.Include("Items").SingleOrDefault(m => m.ID == id); db.tb_OrderDetails.RemoveRange(order.Items); //还需要删除 items 的内容 db.tb_Order.Remove(order); db.SaveChanges(); } }