0 Replies Latest reply on Apr 3, 2012 11:37 AM by 889038

    How to achieve parallel execution of two or more Entity Framework queries?

      Hi Everyone,
      I'm creating some WCF service that use EF to query the database for the data that I need. The problem I have at the moment is that I have 2 or more EF LINQ queries which are declared and then executed to bring back my data... but this is in serial. One EF query is issued, and then the next one after that.
      Does anyone know of a simple way to issue the queries in parallel? Or am I looking at async /parallel tasks to get the correct behaviour.

      I know the DBContext is not thread safe, so I have no problem in declaring multiple contexts if required.

      The code so far is as below:

      +using (IMyContext ctx = MyFactory.GetInstance(request.UserId)) {+

      Response response = new Response();

      response.customer = ctx.GetCustomerByAccount(request.data.Account);
      response.custInfo = ctx.GetCustInfoByAccount(request.data.Account);
      response.address = ctx.GetDefaultAddressByAccount(request.data.Account);

      return response;

      Thanks in advance,