Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Last active April 8, 2016 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcomartin/f8fa34974a72f20434fa to your computer and use it in GitHub Desktop.
Save dcomartin/f8fa34974a72f20434fa to your computer and use it in GitHub Desktop.
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