public virtual int Update<T>(T TObject) where T : class { //ADD LAST MODIFIED DATE IF APPLICABLE if (TObject is IModifiedOn) { (TObject as IModifiedOn).ModifiedOn = DateTime.UtcNow; } var entry = dbContext.Entry(TObject); dbContext.Set<T>().Attach(TObject); entry.State = EntityState.Modified; return dbContext.SaveChanges(); }
/// <summary> /// Updates a single object based on the provided primary key and commits the change /// </summary> /// <remarks>Synchronous</remarks> /// <param name="updated">The updated object to apply to the database</param> /// <param name="key">The primary key of the object to update</param> /// <returns>The resulting updated object</returns> public TObject Update(TObject updated, int key) { if (updated == null) { return(null); } TObject existing = _context.Set <TObject>().Find(key); if (existing != null) { _context.Entry(existing).CurrentValues.SetValues(updated); _context.SaveChanges(); } return(existing); }