Example #1
0
 public static void UpdateDonator(Donator donator)
 {
     using (var db = new Context())
     {
         db.Entry(donator).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
Example #2
0
 public static void UpdateDonatorEnhanced(Donator originalDonator, Donator newDonator)
 {
     using (var db = new Context())
     {
         //从数据库中检索最新的模型
         var donator = db.Donators.Find(originalDonator.Id);
         //接下来检查用户修改的每个属性
         if (originalDonator.Name != newDonator.Name)
         {
             //新值和原始值不同,说明有修改。
             //然后就把新值更新到数据库
             donator.Name = newDonator.Name;
         }
         if (originalDonator.Amount != newDonator.Amount)
         {
             donator.Amount = newDonator.Amount;
         }
         //省略了其他属性的检查
         db.SaveChanges();
     };
 }
Example #3
0
 public static void UpdateDonatorEnhanced(Donator originalDonator,Donator newDonator)
 {
     using(var db=new Context())
     {
         //从数据库中检索最新的模型
         var donator = db.Donators.Find(originalDonator.Id);
         //接下来检查用户修改的每个属性
         if(originalDonator.Name!=newDonator.Name)
         {
             //新值和原始值不同,说明有修改。
             //然后就把新值更新到数据库
             donator.Name = newDonator.Name;
         }
         if (originalDonator.Amount != newDonator.Amount)
         {
             donator.Amount = newDonator.Amount;
         }
         //省略了其他属性的检查
         db.SaveChanges();
     };
 }
Example #4
0
 public static void UpdateDonator(Donator donator)
 {
     using (var db = new Context())
     {
         db.Entry(donator).State = EntityState.Modified;
         db.SaveChanges();
     }
 }