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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:08:08+00:00 2026-06-07T18:08:08+00:00

I’ve written a pretty generic LINQ query which is used throughout my app and

  • 0

I’ve written a pretty generic LINQ query which is used throughout my app and works very well for all cases but one. I’m only running SQL Express at the moment so can’t jump into sql profiler until my download completes, so until then, is there something that stands out in my following LINQ that is going to cause a massive slow down?

Below is a summary of what gets executed. The hold up is of course on the ToList call, and takes a good 30 seconds. I use this code for all my grid views, and only one has the hold up on it. MyGridView is a sql view and in the problem data takes only 2 seconds to execute and return all 16417 records through Sql Management Studio. Finally, it only takes this long when I request pages near the end of the data, so I am assuming it is some how related to the Take and Skip implementation.

private void Demo()
{
    // using LINQ To Entity...
    using (var entities = new MyEntities())
    {
        int page = 1641;
        int pageSize = 10;

        IQueryable<MyGridView> results = entities.MyGridView;

        results = results.Where(r => r.DeletedDate == null);

        var resultCount = results.Count();

        results = ApplyPaging(results, page, pageSize);

        // On the problem data, ToList takes a good 30 seconds to return just 10 records
        var resultList = results.ToList();
    }
}

private IQueryable<T> ApplyPaging<T>(IQueryable<T> data, int currentPage, int pageSize)
{
    if (pageSize > 0 && currentPage > 0)
    {
        data = data.Skip((currentPage - 1) * pageSize);
    }
    data = data.Take(pageSize);
    return data;
}

Anything jump out as being bad, wrong, dangerous? When I get a copy of profiler installed I’ll try and go through the generated sql and post if I find any hints there.

  • 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-07T18:08:09+00:00Added an answer on June 7, 2026 at 6:08 pm

    See http://msdn.microsoft.com/en-us/library/bb357513.aspx#1

    Skip method is very useful with LINQ to SQL to organize server-side
    results paging, and some more things. But there are performance issues
    in some cases, because LINQ can build too difficult SQL queries from
    specified LINQ expressions. I touched this problem with MS SQL Server
    2008. (…)

    (…) if there are 1000000 records in the Orgs table this query will
    be executed very long time because DB server will sort records in
    memory (unlikely you have an appropriate index with all columns
    ordering). And even so simple query

    orgs.Skip(10).Count() requires a significant amount of time, while

    orgs.Count()-10 performes much more quickly 🙂

    Perhaps that’s the root of the problem.

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am writing an app with both english and french support. The app requests

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.