Пример #1
0
 public void AddOrderDB(Order order)
 {
     using (var db = new OrderDB()) {
         db.Order.Add(order);
         //db.Order.Attach(order);
         //db.Entry(order).State = EntityState.Added;
         db.SaveChanges();
     }
 }
Пример #2
0
 public void DeleteDB(string orderId)
 {
     using (var db = new OrderDB()) {
         var order = db.Order.Include("Items").SingleOrDefault(o => o.OrderID == orderId);
         db.OrderItem.RemoveRange(order.Items);
         db.Order.Remove(order);
         db.SaveChanges();
     }
 }
Пример #3
0
 public void Update(Order order)
 {
     using (var db = new OrderDB()) {
         db.Order.Attach(order);
         db.Entry(order).State = EntityState.Modified;
         order.Items.ForEach(
             item => db.Entry(item).State = EntityState.Modified);
         db.SaveChanges();
     }
 }
Пример #4
0
 public void AddOrderEF(Order order)
 {
     using (OrderDB db = new OrderDB()) {
         try {
             db.Order.Add(order);
             //db.Order.Attach(order);
             //db.Entry(order).State = EntityState.Added;
             db.SaveChanges();
         }
         catch (Exception ex) {                }
     }
 }