I faced with deadlock when trying make two parallel calls to DB in action
public async Task<IActionResult> Index(){
var firstTask = this._uow.GetCountries(); //create task to run it in background
var secondResult = await _uow.GetStates(); //call method and get result from Task
var firstResult = await firstTask; //trying to get result from first task
return View();
}
And unit of work methods are simple and use Entity framework:
public async Task<Countries> GetCountries()
{
return await dbContext.Countries.ToListAsync(); //
}
public async Task<States> GetStates()
{
return await dbContext.States.ToListAsync();
}
Anyway call this methods like this will fix issue and i wonder why?
public async Task<IActionResult> Index(){
var secondResult = await _uow.GetStates();
var firstResult = await _uow.GetCountries();
return View();
}
But with this i'm losing main idea - parallel calls