예제 #1
0
 public int Save()
 {
     //return context.SaveChanges();
     try
     {
         return(context.SaveChanges());
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
     {
         Exception raise = dbEx;
         foreach (var validationErrors in dbEx.EntityValidationErrors)
         {
             foreach (var validationError in validationErrors.ValidationErrors)
             {
                 string message = string.Format("{0}:{1}",
                                                validationErrors.Entry.Entity.ToString(),
                                                validationError.ErrorMessage);
                 // raise a new exception nesting
                 // the current instance as InnerException
                 raise = new InvalidOperationException(message, raise);
             }
         }
         throw raise;
     }
 }
예제 #2
0
 public void AddLastLogin(DomainEntity.LastLoginEntity entity)
 {
     try
     {
         using (var datacontext = new LoginData.RAL_DevEntities())
         {
             datacontext.Last_LogIn.Add(_mapper.Map <DomainEntity.LastLoginEntity, LoginData.Last_LogIn>(entity));
             datacontext.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
 }