Entity Framework with Parallel Library RRS feed

  • Question

  • Hello !!

    I have an question on entity framework with Parallel.Foreach() .. it seems ObjectContext is not thread safe.. what options do I have now if i want my program to use parallel library?

    Details -

    I have a program that generates large JSON files for products.. i am using parallel.foreach over the list of products which generates the JSON file after consolidating and fetching data from product database and tags from CMS.. For each product I used EF to query product database and CMS to fetch data.. As long as my main program used Foreach(), it was fine.. the moment i started using Parallel.Foreach(), it started giving errors..

    My product list is huge. Its over 5000. There has to be 1 JSON file per product. So i wanted to speed up the process by introducing Parallel.Foreach(). However most cases I get "The underlying provider failed on open" error.

    Any response would be highly appreciated..



    Wednesday, September 12, 2012 3:22 AM

All replies

  • Hi DJ;

    Parallel.Foreach works with local collections and can not be placed inside a query. Please post your code so we can see how it is being used.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Wednesday, September 12, 2012 4:36 PM
  • Hi Debajyoti Basu,

    I agree with @Fernando, could you please post some code here? This is, so we can help you more effectively.

    Best Regards

    Allen Li [MSFT]
    MSDN Community Support | Feedback to us

    Friday, September 14, 2012 1:19 AM