public void Update(T item) { try { using (context) { var entity = context.Set <T>().Where(t => t.Id == item.Id).FirstOrDefault(); if (entity != null) { context.Entry(entity).CurrentValues.SetValues(item); context.SaveChanges(); } } } catch (DbEntityValidationException dbEx) { var msg = string.Empty; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { msg += Environment.NewLine + $"Property: {validationError.PropertyName} Error: {validationError.ErrorMessage}"; } } var fail = new Exception(msg, dbEx); throw fail; } }
public void Update(T item) { try { using (context) { var entity = context.Set <T>().FirstOrDefault(t => t.Id == item.Id); if (entity != null) { context.Entry(entity).CurrentValues.SetValues(item); context.SaveChanges(); } } } catch (DbEntityValidationException dbEx) { throw dbEx; } }
public Repository(AppContext context) { this.context = context; try { table = context.Set <T>(); } catch (Exception e) { throw e; } }
public Repository() { context = new AppContext(); table = context.Set <T>(); }
public Repository(AppContext context) { this.context = context; table = context.Set <T>(); }