Last active
February 5, 2020 12:12
-
-
Save CaCTuCaTu4ECKuu/5a6dc2e76ced8d594648a7df163d10fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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