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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:29:56+00:00 2026-06-10T14:29:56+00:00

I have the following query: if (idUO > 0) { query = query.Where(b =>

  • 0

I have the following query:

if (idUO > 0)
{
    query = query.Where(b => b.Product.Center.UO.Id == idUO);
}
else if (dependencyId > 0)
{
    query = query.Where(b => b.DependencyId == dependencyId );
}
else
{
    var dependencyIds = dependencies.Select(d => d.Id).ToList();

    query = query.Where(b => dependencyIds.Contains(b.DependencyId.Value));
}

[...] <- Other filters...

if (specialDateId != 0)
{
    query = query.Where(b => b.SpecialDateId == specialDateId);
}

So, I have other filters in this query, but at the end, I process the query in the database with:

return query.OrderBy(b => b.Date).Skip(20 * page).Take(20).ToList(); // the returned object is a Ticket object, that has 23 properties, 5 of them are relationships (FKs) and i fill 3 of these relationships with lazy loading

When I access the first page, its OK, the query takes less than one 1 second, but when I try to access the page 30000, the query takes more than 20 seconds. There is a way in the linq query, that I can improve the performance of the query? Or only in the database level? And in the database level, for this kind of query, which is the best way to improve the performance?

  • 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-10T14:29:57+00:00Added an answer on June 10, 2026 at 2:29 pm

    I think you’ll find that the bottleneck is occurring at the database. Here’s why;

    query.

    You have your query, and the criteria. It goes to the database with a pretty ugly, but not too terrible select statement.

    .OrderBy(b => b.Date)

    Now you’re ordering this giant recordset by date, which probably isn’t a terrible hit because it’s (hopefully) indexed on that field, but that does mean the entire set is going to be brought into memory and sorted before any skipping or taking occurs.

    .Skip(20 * page).Take(20)

    Ok, here’s where it gets rough for the poor database. Entity is pretty awful at this sort of thing for large recordsets. I dare you to open sql profiler and view the random mess of sql it’s sending over.

    When you start skipping and taking, Entity usually sends queries that coerce the database into scanning the entire giant recordset until it finds what you are looking for. If that’s the first ordered records in the recordset, say page 1, it might not take terribly long. By the time you’re picking out page 30,000 it could be scanning a lot of data due to the way Entity has prepared your statement.

    I highly recommend you take a look at the following link. I know it says 2005, but it’s applicable to 2008 as well.

    http://www.codeguru.com/csharp/.net/net_data/article.php/c19611/Paging-in-SQL-Server-2005.htm

    Once you’ve read that link, you might want to consider how you can create a stored procedure to accomplish what you’re going for. It will be more lightweight, have cached execution plans, and is pretty well guaranteed to return the data much faster for you.

    Barring that, if you want to stick with LINQ, read up on Compiled Queries and make sure you’re setting MergeOption.NoTracking for read-only operations. You should also try returning an Object Query with explicit Joins instead of an IQueryable with deferred loading, especially if you’re iterating through the results and joining to other tables. Deferred Loading can be a real performance killer.

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

Sidebar

Related Questions

I have following query select * from table1 if table1 contains text type column/columns
I have following query, var employees = from emp in this.DataWorkspace.v2oneboxData.me_employees where emp.me_is_deleted.Value ==
I have following query Select a,b,c, case totalcount when 0 then 0 else abcd/totalcount
I have following query: $query=SELECT language_value, votes, user_id FROM labels WHERE approved=1 AND label_value=.
I have following query , select * from process where name like 'abc'; now
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
I have the following query to count all data every minute. $sql= SELECT COUNT(*)
I have the following query: SELECT item.`ID`, item.`Name`, item.`UnitCost`, item.`Price`, discount.`rate` FROM item INNER
I have the following query to select users and their locations, etc from MySQL
i have following query working.. select count(id) , case when age < 0 then

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.