예제 #1
0
 public void AddOrder(Order order)
 {
     using (var db = new OrderDB())
     {
         db.tb_Order.Add(order);
         db.SaveChanges();
     }
 }
예제 #2
0
 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();
     }
 }
예제 #3
0
 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();
     }
 }