Beispiel #1
0
 public IEnumerable <DeviceTypeModel> Get()
 {
     using (var db = new TestHXContext())
     {
         List <DeviceTypeModel> list = db.DeviceType.ToList();
         return(list);
     }
 }
Beispiel #2
0
 public void Add(DeviceTypeModel instance)
 {
     using (var db = new TestHXContext())
     {
         db.DeviceType.Add(instance);
         db.SaveChanges();
     }
 }
Beispiel #3
0
 public void Delete(DeviceModel instance)
 {
     using (var db = new TestHXContext())
     {
         db.Entry <DeviceModel>(instance).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
     }
 }
Beispiel #4
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();
     }
 }