//添加
 public void Add(Order order)
 {
     using (var db = new OrderDB())
     {
         db.Order.Add(order);
         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();
     }
 }
        //删除
        public void Delete(int KeyId)
        {
            using (var db = new OrderDB())
            {
                db.OrderDetail.Include("Good").ToList <OrderDetails>();
                var order = db.Order.Include("details").SingleOrDefault(o => o.Id == KeyId);
                foreach (var good in order.details)
                {
                    db.Good.Remove(good.Good);
                }

                db.OrderDetail.RemoveRange(order.details);
                db.Order.Remove(order);
                db.SaveChanges();
            }
        }