fun with transactions
This commit is contained in:
@@ -199,14 +199,10 @@ namespace AyaNova.Biz
|
||||
//collect the child id's to delete
|
||||
var ItemIds = await ct.WorkOrderItem.Where(m => m.WorkOrderId == id).Select(m => m.Id).ToListAsync();
|
||||
|
||||
|
||||
//Delete children
|
||||
foreach (long ItemId in ItemIds)
|
||||
{
|
||||
if (!await ItemDeleteAsync(ItemId, transaction))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
ct.WorkOrder.Remove(dbObject);
|
||||
await ct.SaveChangesAsync();
|
||||
@@ -422,8 +418,9 @@ namespace AyaNova.Biz
|
||||
//
|
||||
internal async Task<bool> ItemDeleteAsync(long id, Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction parentTransaction = null)
|
||||
{
|
||||
using (var transaction = parentTransaction ?? await ct.Database.BeginTransactionAsync())
|
||||
{
|
||||
Microsoft.EntityFrameworkCore.Storage.IDbContextTransaction transaction = null;
|
||||
if (parentTransaction == null)
|
||||
transaction = await ct.Database.BeginTransactionAsync();
|
||||
try
|
||||
{
|
||||
WorkOrderItem dbObject = await ct.WorkOrderItem.SingleOrDefaultAsync(m => m.Id == id);
|
||||
@@ -463,11 +460,14 @@ namespace AyaNova.Biz
|
||||
{
|
||||
//Just re-throw for now, let exception handler deal, but in future may want to deal with this more here
|
||||
throw;
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (parentTransaction == null)
|
||||
await transaction.DisposeAsync();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user