public bool Insert(TEntity entity) { try { dbSet.Add(entity); context.SaveChanges(); return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error: {0},\nStackTrace: {1}", ex.Message, ex.StackTrace); return(false); } }
public void InsertCollection(List <TEntity> entityCollection) { try { entityCollection.ForEach(e => { dbSet.Add(e); }); context.SaveChanges(); } catch (DbEntityValidationException ex) { StringBuilder sb = new StringBuilder(); foreach (var failure in ex.EntityValidationErrors) { sb.AppendFormat("{0} failed validation\n", failure.Entry.Entity.GetType()); foreach (var error in failure.ValidationErrors) { sb.AppendFormat("- {0} : {1}", error.PropertyName, error.ErrorMessage); sb.AppendLine(); } } throw new DbEntityValidationException( "Entity Validation Failed - errors follow:\n" + sb.ToString(), ex ); } }