Exemple #1
0
 public void Add(DeviceTypeModel instance)
 {
     using (var db = new TestHXContext())
     {
         db.DeviceType.Add(instance);
         db.SaveChanges();
     }
 }
Exemple #2
0
 public void Delete(DeviceModel instance)
 {
     using (var db = new TestHXContext())
     {
         db.Entry <DeviceModel>(instance).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
 }
Exemple #3
0
 public void Delete(DeviceTypeModel instance)
 {
     using (var db = new TestHXContext())
     {
         DeviceTypeModel dtm = db.DeviceType.Find(instance.Id);
         db.Entry <DeviceTypeModel>(dtm).State = System.Data.Entity.EntityState.Deleted;
         //获取关联的设备并更新外键为Null
         var d = db.Device.Where(a => a.TypeId == instance.Id);
         foreach (var item in d)
         {
             item.TypeId = null;
         }
         db.SaveChanges();
     }
 }