コード例 #1
0
 public bool RemoveRange(List <T> list, out string msg)
 {
     msg = string.Empty;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             context.Set <T>().RemoveRange(list);
             return(context.SaveChanges() > 0);
         }
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var item1 in ex.EntityValidationErrors)
         {
             foreach (var item2 in item1.ValidationErrors)
             {
                 msg += item2.ErrorMessage + "<br />";
             }
         }
         return(false);
     }
 }
コード例 #2
0
 public bool Update(T entity, out string msg)
 {
     msg = string.Empty;
     try
     {
         using (L_Sys context = new L_Sys())
         {
             context.Set <T>().Attach(entity);
             context.Entry <T>(entity).State = EntityState.Modified;
             return(context.SaveChanges() > 0);
         }
     }
     catch (DbEntityValidationException ex)
     {
         foreach (var item1 in ex.EntityValidationErrors)
         {
             foreach (var item2 in item1.ValidationErrors)
             {
                 msg += item2.ErrorMessage + "<br />";
             }
         }
         return(false);
     }
 }