I'm trying to insert records in two tables, but getting the exception. Could you please help me to resolve the issue.
First I tried the below code.
await _testRepository.InsertAsync(test);
await _xyzRepository.InsertAsync(xyz);
Then I tried this code, But nothing is working for me.
try
{
var test = new Test();
using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
{
int? tenantId = _unitOfWorkManager.Current.GetTenantId();
using (_unitOfWorkManager.Current.SetTenantId(tenantId))
{
await _testRepository.InsertAsync(test);
var xyz = new XYZ();
await _xyzRepository.InsertAsync(xyz);
await _unitOfWorkManager.Current.SaveChangesAsync();
await uow.CompleteAsync();
}
}
}
catch (Exception ex)
{
throw new UserFriendlyException(ex.Message);
}
Exception
Message:
Database operation expected to affect 1 row(s) but actually affected 0
row(s). Data may have been modified or deleted since entities were
loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for
information on understanding and handling optimistic concurrency
exceptions.
stack trace:
at
Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch.ThrowAggregateUpdateConcurrencyException(Int32
commandIndex, Int32 expectedRowsAffected, Int32 rowsAffected) at
Microsoft.EntityFrameworkCore.Update.AffectedCountModificationCommandBatch