1async Task<List<E1Entity>> GetE1Data()
2{
3 using(var MyCtx = new MyCtx())
4 {
5 return await MyCtx.E1.Where(bla bla bla).ToListAsync();
6 }
7}
8
9async Task<List<E2Entity>> GetE2Data()
10{
11 using(var MyCtx = new MyCtx())
12 {
13 return await MyCtx.E2.Where(bla bla bla).ToListAsync();
14 }
15}
16
17async Task DoSomething()
18{
19 var t1 = GetE1Data();
20 var t2 = GetE2Data();
21 await Task.WhenAll(t1,t2);
22 DoSomething(t1.Result, t2.Result);
23}
1EF doesn't support processing multiple requests through the same DbContext object.
2If your second asynchronous request on the same DbContext instance starts before the first request finishes (and that's the whole point),
3you'll get an error message that your request is processing against an open DataReader.