Skip to content

Instantly share code, notes, and snippets.

@dcomartin dcomartin/context.cs

Last active Apr 8, 2016
Embed
What would you like to do?
public async Task<int> SaveChangesAsync(Guid messageId)
{
using (var transaction = Database.BeginTransaction())
{
var result = await SaveChangesAsync();
IdempotentIds.Add(new Idempotent { IdempotentId = messageId });
try
{
await SaveChangesAsync();
}
catch (DbUpdateException ex)
{
// Duplicate Key Error Number
if (ex.InnerException?.InnerException != null && (ex.InnerException.InnerException as MySqlException)?.Number == 1062) return 0;
throw;
}
transaction.Commit();
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.