Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using (var tran = await _dbContext.BeginTransactionAsync())
var modelsToRemove = await _dbContext.QueryModels
.Where(f => /* some filter here */)
if (modelsToRemove.Any())
// remenber to call SaveChangesAsync() after every write in order to
// ensure that the operation has been performed.
// The Ef DbContext is not thread safe and if there are multiple instances of the
// service, data might not be persisted correctly.
await _dbContext.SaveChangesAsync();
if (newModels?.Any())
await _dbContext.SaveChangesAsync();
catch (Exception ex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment