public virtual T Insert(T entity) { try { if (entity == null) { throw new ArgumentNullException("entity"); } var result = Table.Add(entity); Context.SaveChanges(); return(result); } catch (DbEntityValidationException dbEx) { var msg = string.Empty; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { msg += string.Format("Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage) + Environment.NewLine; } } var fail = new Exception(msg, dbEx); throw fail; // result = false; } }
public void Save() { Context.SaveChanges(); }