Skip to content

Instantly share code, notes, and snippets.

@CaCTuCaTu4ECKuu
Last active February 5, 2020 12:12
Show Gist options
  • Save CaCTuCaTu4ECKuu/5a6dc2e76ced8d594648a7df163d10fc to your computer and use it in GitHub Desktop.
Save CaCTuCaTu4ECKuu/5a6dc2e76ced8d594648a7df163d10fc to your computer and use it in GitHub Desktop.
public virtual async Task UpdateAsync(T entity)
{
if (entity == null)
throw new ArgumentNullException(nameof(entity));
if (!IsAttached(entity, out EntityEntry<T> entry))
{
Entities.Attach(entity);
_dbContext.Entry(entity).State = EntityState.Modified;
}
if (entry.State != EntityState.Unchanged)
{
try
{
await _dbContext.SaveChangesAsync()
.ConfigureAwait(false);
}
catch (Exception ex)
{
var error = ex.Message;
}
OnUpdate?.Invoke(this, new[] { entity });
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment