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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:09:45+00:00 2026-05-24T23:09:45+00:00

I have this function below that takes a list of id’s and searches the

  • 0

I have this function below that takes a list of id’s and searches the DB for the matching persons.

public IQueryable<Person> GetPersons(List<int> list)
{
    return db.Persons.Where(a => list.Contains(a.person_id));
}  

The reason I need to split this into four queries is because the query can’t take more than 2100 comma-separated values:
The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Too many parameters were provided in this RPC request. The maximum is 2100.

How can I split the list into 4 pieces and make a query for each list. Then join the results into one list of persons?

Solved
I don’t want to post it as an own answer and take cred away from @George Duckett’s answer, just show the solution:

public IQueryable<Person> GetPersons(List<int> list)
    {
        var persons = Enumerable.Empty<Person>().AsQueryable<Person>();
        var limit = 2000;
        var result = list.Select((value, index) => new { Index = index, Value = value })
                 .GroupBy(x => x.Index / limit)
                 .Select(g => g.Select(x => x.Value).ToList())
                 .ToList();

        foreach (var r in result)
        {
            var row = r;
            persons = persons.Union(db.Persons.Where(a => row.Contains(a.person_id)));
        }
        return persons;
    }
  • 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-24T23:09:46+00:00Added an answer on May 24, 2026 at 11:09 pm

    See this answer for splitting up your list: Divide a large IEnumerable into smaller IEnumerable of a fix amount of item

    var result = list.Select((value, index) => new { Index = index, Value = value})
                  .GroupBy(x => x.Index / 5)
                  .Select(g => g.Select(x => x.Value).ToList())
                  .ToList();
    

    Then do a foreach over the result (a list of lists), using the below to combine them.

    See this answer for combining the results: How to combine Linq query results

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

Sidebar

Related Questions

I have the jquery code below that returns a list of ID's like this
I have written a function below that takes a pointer to the front of
I have the below prog Object.prototype.inherit = function(baseConstructor) { this.prototype = (baseConstructor.prototype); this.prototype.constructor =
I have this function that I would like to condense into some iterator. How
I have created a function that takes a SQL command and produces output that
I have a very simple function which takes in a matching bitfield, a grid,
I have this function // add history paths and save data function AddPath( strTag,
I have this function: int firstHeapArray (IntHeapArray h) { if(!emptyHeapArray(h)) return h.array[0]; } It's
I have this function to create a request to another file to update the
I have this function: function validate($data) { $newData = str_replace(&nbsp;, , $newData); $newData =

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.