In the .NET core web API application we are using MS SQL transactions in one service method and in the middle of that method, we are calling another service method, inside this method when trying to insert a new model entry it throws errors like " cannot issue save transaction when there is no active transaction", how we can resolve it? We are using a repository pattern.
Class A
{
A(Repos_A _repo_a,ServiceB service)
{
////
}
void Method_A()
{
using var transaction = _dBContext.Database.BeginTransaction();
_repo_a.Add(DBmodel).Wait();
_repo_a.SaveAsnc().Wait();
service.Method_B();
transaction.Commit();
}
}
class ServiceB
{
ServiceB(Repos_B _repo_B,ServiceB service)
{
////
}
void Method_B()
{
_repo_B.Add(DBmodel).Wait();
_repo_B.SaveAsnc().Wait();//Error throws in this line " cannot issue save transaction when there is no active transaction"
}
}