Task task1 = serviceA.DoSomething();
Task task2 = serviceB.DoSomethingElse();
await Task.WhenAll(task1, task2);
Services have no idea that they are operating on database, however if both tasks end up querying one database there will be concurrency exception.
As described in Does Entity Framework support parallel async queries? EF does not support multiple async queries.
Is there pattern or some way to queue such queries/commands and execute them one after another (but still speed up execuition if they are hitting separate database)?
Maybe better solution would be to change dbContext from per-request to transient and new up dbContext with separate connection for each query? What are performance implications of this? First that I see is separate transaction for each dbcontext and commiting them all instead of single transaction.