I'm developing a .NET Core web api service and have the following method in BL:
public async Task<SetParams> GetParams(CreateRequest request)
{
var user = await _userRepository.GetUserByLogin(request.Login);
var client = await _clientRepository.GetClientByCode( request.ClientCode);
// many other getters here
return new SetParams
{
IdUser = user.IdUser,
ClientName = client.Name,
// and so forth...
};
}
I have a requirement to get all the entities in "dirty read" mode.
So, I was trying to use TransactionScope this way:
public async Task<SetParams> GetParams(CreateRequest request)
{
using (var ts = new TransactionScope(
TransactionScopeOption.Required,
new TransactionOptions { IsolationLevel = IsolationLevel.ReadUncommitted }))
{
var user = await _userRepository.GetUserByLogin(request.Login);
var client = await _clientRepository.GetClientByCode(request.ClientCode);
// many other getters here
ts.Complete();
return new SetParams
{
IdUser = user.IdUser,
ClientName = client.Name,
// and so forth...
};
}
}
But: 1) this has read committed mode (I know from this post that I have to start a transaction but I don't have a session or db context here, because I'm in BL not in DAL)
and 2) ending up with an exception A TransactionScope must be disposed on the same thread that it was created.