public void Save()
        {
            //_context.SaveChanges();
            try
            {
                _context.SaveChanges();
            }
            catch (DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;
                foreach (DbEntityValidationResult validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (DbValidationError validationError in validationErrors.ValidationErrors)
                    {
                        var message = string.Format("{0}:{1}",
                                                    validationErrors.Entry.Entity,
                                                    validationError.ErrorMessage);
                        // raise a new exception nesting
                        // the current instance as InnerException
                        raise = new InvalidOperationException(message, raise);
                    }
                }

                throw raise;
            }
        }
Exemplo n.º 2
0
 public void Save()
 {
     _context.SaveChanges();
 }