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 881655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:17:50+00:00 2026-05-15T12:17:50+00:00

I have a piece of code which combines an in-memory list with some data

  • 0

I have a piece of code which combines an in-memory list with some data held in a database. This works just fine in my unit tests (using a mocked Linq2SqlRepository which uses List).

    public IRepository<OrderItem> orderItems { get; set; }

    private List<OrderHeld> _releasedOrders = null;
    private List<OrderHeld> releasedOrders
    {
        get
        {
            if (_releasedOrders == null)
            {
                _releasedOrders = new List<nOrderHeld>();
            }
            return _releasedOrders;
        }
    }

    .....

    public int GetReleasedCount(OrderItem orderItem)
    {
        int? total =
            (
                from item in orderItems.All
                join releasedOrder in releasedOrders
                    on item.OrderID equals releasedOrder.OrderID
                where item.ProductID == orderItem.ProductID
                select new
                {
                    item.Quantity,
                }

            ).Sum(x => (int?)x.Quantity);

        return total.HasValue ? total.Value : 0;
    }

I am getting an error I don’t really understand when I run it against a database.

Exception information:
    Exception type: System.NotSupportedException
    Exception message: Local sequence cannot be used in LINQ to SQL
implementation of query operators
except the Contains() operator.

What am I doing wrong?

I’m guessing it’s to do with the fact that orderItems is on the database and releasedItems is in memory.


EDIT

I have changed my code based on the answers given (thanks all)

    public int GetReleasedCount(OrderItem orderItem)
    {
        var releasedOrderIDs = releasedOrders.Select(x => x.OrderID);

        int? total =
            (
                from item in orderItems.All
                where releasedOrderIDs.Contains(item.OrderID)
                   && item.ProductID == orderItem.ProductID
                select new
                {
                    item.Quantity,
                }

            ).Sum(x => (int?)x.Quantity);

        return total.HasValue ? total.Value : 0;
    }
  • 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-05-15T12:17:51+00:00Added an answer on May 15, 2026 at 12:17 pm

    I’m guessing it’s to do with the fact
    that orderItems is on the database
    and releasedItems is in memory.

    You are correct, you can’t join a table to a List using LINQ.

    Take a look at this link:

    http://flatlinerdoa.spaces.live.com/Blog/cns!17124D03A9A052B0!455.entry

    He suggests using the Contains() method but you’ll have to play around with it to see if it will work for your needs.

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

Sidebar

Related Questions

I have following piece of code which posts some data into database: $post =
I have this piece of code which works 90% of the time: $user_details=$fb->api_client->users_getInfo($fb_user, array('last_name','first_name','proxied_email'));
I have this piece of code which works, however I would like to change
I have some piece of code which goes like this: pipe(fd); child_map[0] = fd[0];
I have this piece of code which is calling some functions in a web
I have this piece of code which compiles and works as expected: #include <iostream>
I have this piece of code which works in Firefox link = $('<a>link</a>'); var
I have this piece of code which I am using to update some values
I have this piece of code which check the last customer_id from the db.
I have this piece of code which I'm hoping will be able to tell

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.