Answers for "how to run parallel queries in sql server with entity framework"

SQL
1

how to run parallel queries in sql server with entity framework

async Task<List<E1Entity>> GetE1Data()
{
    using(var MyCtx = new MyCtx())
    {
         return await MyCtx.E1.Where(bla bla bla).ToListAsync();
    }
}

async Task<List<E2Entity>> GetE2Data()
{
    using(var MyCtx = new MyCtx())
    {
         return await MyCtx.E2.Where(bla bla bla).ToListAsync();
    }
}

async Task DoSomething()
{
    var t1 = GetE1Data();
    var t2 = GetE2Data();
    await Task.WhenAll(t1,t2);
    DoSomething(t1.Result, t2.Result);
}
Posted by: Guest on March-25-2020
0

how to run parallel queries in sql server with entity framework

EF doesn't support processing multiple requests through the same DbContext object.
If your second asynchronous request on the same DbContext instance starts before the first request finishes (and that's the whole point),
you'll get an error message that your request is processing against an open DataReader.
Posted by: Guest on March-25-2020

Code answers related to "how to run parallel queries in sql server with entity framework"

Code answers related to "SQL"

Browse Popular Code Answers by Language