Base solution for your next web application
Open Closed

multiple async calls with same parent context (irepository) #668


User avatar
0
daws created

Hi :D

I have a console application which needs to call several different repository.GetAllListAsync() methods. I'm trying to get the different calls to run in parallel with Task.WaitAll in my main method.

However, since all repositories share the same context, I get the following error: "A second operation started on this context before a previous asynchronous operation completed.".

Is there a way for my console application to run each GetAllListAsync() call in parallel ?

Thanks


1 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    If you are not in a UOW, there is no problem. They will all use their own UOW and dbcontext. So, be sure to not start a UOW while using them. If this is not possible, there is no way since this is a restriction of EF.

    Have a nice day :)