Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8799273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:16:51+00:00 2026-06-14T00:16:51+00:00

Hello I have just started to try and understand Parallel Linq and with my

  • 0

Hello I have just started to try and understand Parallel Linq and with my first attempt I am having no success. I am using EF 4.0 and a repository pattern class that I created to query the data. I don’t believe that the repository pattern is the problem but I could be mistaken.

The database that I have isn’t setup the way that I would like it but hey I inherited the system. The code that I am having the problem with is below:

            var gId = Sql.ToGuid(Request["ID"]);

            var lOrdersGridList = new OrdersGridList(); //Class that only contains properties

            var lOrdersForContact = new BaseRepository<ORDER>()
                .Find(i => i.ORDERS_CONTACTS.Where(b => b.CONTACT_ID == gId).Count() > 0).AsParallel()
                .Select(i =>
                    new OrdersGridList
                        {
                            ORDER_ID = i.ID,
                            ORDER_NUM = i.ORDER_NUM,
                            SHIPPING_ACCOUNT_ID = i.ORDERS_ACCOUNTS.Where(b =>  b.ORDER_ID == i.ID && b.ACCOUNT_ROLE == "Ship To").First().ACCOUNT_ID,
                            SHIPPING_ACCOUNT_NAME = i.ORDERS_ACCOUNTS.Where(b => b.ORDER_ID == i.ID && b.ACCOUNT_ROLE == "Ship To").First().ACCOUNT.NAME,
                            SHIPPING_CONTACT_ID = i.ORDERS_CONTACTS.Where(b => b.ORDER_ID == i.ID && b.CONTACT_ROLE == "Ship To").First().CONTACT_ID,
                            SHIPPING_CONTACT_NAME = i.ORDERS_CONTACTS.Where(b => b.ORDER_ID == i.ID && b.CONTACT_ROLE == "Ship To")
                                                                .Select(b => new { SHIPPING_CONTACT_NAME = (b.CONTACT.FIRST_NAME + ' ' + b.CONTACT.LAST_NAME) }).First().SHIPPING_CONTACT_NAME,
                            NAME = i.NAME

                        }).DefaultIfEmpty(lOrdersGridList).ToList<OrdersGridList>();


            grdMain.DataSource = lOrdersForContact.ToDataTable().DefaultView; //ToDataTable extension function converts the List Object to a datatable.

If I run the Code without AsParallel the code executes with no problem however, once I add AsParallel I receive the following error:

error message

Also just in case you wanted to see this is the class that I am declaring as new for the Select Above:

public class OrdersGridList : EntityObject
{
    public string ORDER_NUM { get; set; }

    public Guid ORDER_ID { get; set; }

    public Guid SHIPPING_ACCOUNT_ID { get; set; }

    public string SHIPPING_ACCOUNT_NAME { get; set; }

    public Guid SHIPPING_CONTACT_ID { get; set; }

    public string SHIPPING_CONTACT_NAME { get; set; }

    public string NAME { get; set; }
}

If I remove all of the relationships that are used to retrieve data in the select I don’t receive any errors:

                var lOrdersForContact = new BaseRepository<ORDER>()
                .Find(i => i.ORDERS_CONTACTS.Where(b => b.CONTACT_ID == gId).Count() > 0).AsParallel()
                .Select(i =>
                    new OrdersGridList
                        {
                            ORDER_ID = i.ID,
                            ORDER_NUM = i.ORDER_NUM,
                            //SHIPPING_ACCOUNT_ID = i.ORDERS_ACCOUNTS.Where(b =>  b.ORDER_ID == i.ID && b.ACCOUNT_ROLE == "Ship To").First().ACCOUNT_ID,
                            //SHIPPING_ACCOUNT_NAME = i.ORDERS_ACCOUNTS.Where(b => b.ORDER_ID == i.ID && b.ACCOUNT_ROLE == "Ship To").First().ACCOUNT.NAME,
                            //SHIPPING_CONTACT_ID = i.ORDERS_CONTACTS.Where(b => b.ORDER_ID == i.ID && b.CONTACT_ROLE == "Ship To").First().CONTACT_ID,
                            //SHIPPING_CONTACT_NAME = i.ORDERS_CONTACTS.Where(b => b.ORDER_ID == i.ID && b.CONTACT_ROLE == "Ship To")
                            //                                    .Select(b => new { SHIPPING_CONTACT_NAME = (b.CONTACT.FIRST_NAME + ' ' + b.CONTACT.LAST_NAME) }).First().SHIPPING_CONTACT_NAME,
                            NAME = i.NAME

                        }).DefaultIfEmpty(lOrdersGridList).ToList<OrdersGridList>();

I would be more than happy to give more information if required. Any help you can provide on using PLinq I would appreciate it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T00:16:53+00:00Added an answer on June 14, 2026 at 12:16 am

    To me it appears like the BaseRepository class creates some kind of LINQ to Entities query using the Find and Select parameters.

    Using AsParellel is made for LINQ to Objects, where your code actually evaluates the expressions you pass. Other LINQ dialects, including LINQ to Entities, translate it into a different query language like SQL. The SQL server may do reasonable parallelisation itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started the Hello World App using Blackberry Eclipse Plugin. I have
Hello I have just started doing some parsing in bison/yacc. Now my first program
I have just put the first step in android,and just started with hello android
Hello i have just started learning mvc2 and im having a problem with the
hello i have just start using Raphael but i'm very confused in the following
I have just started with Android with the usual Hello World project template in
I have just started learning Javascript. I want Hello World! to be written to
Hello there people of stack overflow, I have just started developing with android and
I have just started learning how to program Windows GUI's using the low level
Hello! I have just started playing with android layouts and i wonder if there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.