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

  • Home
  • SEARCH
  • 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 3213586
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:57:42+00:00 2026-05-17T14:57:42+00:00

I am using Linq to Sql as my ORM and I have a list

  • 0

I am using Linq to Sql as my ORM and I have a list of Ids (up to a few thousand) passed into my retriever method, and with that list I want to grab all User records that correspond to those unique Ids. To clarify, imagine I have something like this:

List<IUser> GetUsersForListOfIds(List<int> ids)
{
        using (var db = new UserDataContext(_connectionString))
        {
            var results = (from user in db.UserDtos
                           where ids.Contains(user.Id)
                           select user);

            return results.Cast<IUser>().ToList();
        }
}

Essentially that gets translated into sql as

select * from dbo.Users where userId in ([comma delimmited list of Ids])

I’m looking for a more efficient way of doing this. The problem is the in clause in sql seems to take too long (over 30 seconds).

  • 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-17T14:57:43+00:00Added an answer on May 17, 2026 at 2:57 pm

    Will need more information on your database setup like index’s and type of server (Mitch Wheat’s post). Type of database would help as well, some databases handle in clauses poorly.

    From a trouble shooting standpoint…have you isolated the time delay to the sql server? Can you run the query directly on your server and confirm it’s the query taking the extra time?

    Select * can also have a bit of a performance impact…could you narrow down the result set that’s being returned to just the columns you require?

    edit: just saw the ‘view comment’ that you added…I’ve had problems with view performance in the past. Is it a materialized view…or could you make it into one? Recreating the view logic as a stored procedure may aslo help.

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

Sidebar

Related Questions

Using LINQ to SQL, I have an Order class with a collection of OrderDetails.
I'm using LINQ to SQL and C#. I have two LINQ classes: User and
We are using Linq To SQL with our own data context logic that executes
I have started using Linq to SQL in a (bit DDD like) system which
We are using Linq To SQL with our own data context logic that executes
I have been using LINQ to SQL for a while, and there is one
I am using linq to sql as ORM for my asp.net mvc website. I
I'm using Linq to Sql and have a Many-To-Many relation and therefore use a
Using LINQ or SQL, how could I have the following strings, normally sorted as:
Iam using linq to SQl, And I have some Serilization problem, For Example I

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.