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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:46:28+00:00 2026-06-01T10:46:28+00:00

We have a data grid to display member records for our clients. We recently

  • 0

We have a data grid to display member records for our clients. We recently were tasked to add paging to our application so that our large clients (500,000+ members).

Our table that we grab the data from has 10 columns. When pull our data into our application we added 3 additional columns that are all calculated fields

i.e.

SELECT SUM(tableX.Cost) FROM tableX WHERE tableX.ID = this_.ID

where “this_” is the alias for our members table and tableX represents the other table that we need to grab data from.

In our query we must provide the ability to order the columns, but i’ve noticed that when I try to order the calculated fields that it takes a significant amount of time compared to when I ORDER BY an column that exists in the table. This makes sense that it takes longer, but when it takes a couple minutes to load only 1000 records and there will be 500+ pages to go through. Then I feel this makes paging pointless.

I’ve looked a bit into maybe doing a 2nd level cache with nhibernate, but from what i’ve read so far i’m not sure if will solve this problem.

By the way one of the maps is:

Map(x => x.Cost)
    .Formula(@"(SELECT SUM(_Claims.Cost) FROM _Claims WHERE _Claims.ID = this_.ID")
    .Nullable();

and for the query

    var list = CurrentSession()
               .SetFirstRsult(startPos)
               .SetMaxResults(1000)
               .SetTimeout(100)
               .Add(Restrictions.Eq("ClientID", _clientID));

    if(isASC)
    {
        list.AddOrder(Order.Asc(Projetions.Property(_propertyString)));
    }
    else
    {
        list.AddOrder(Order.Desc(Projetions.Property(_propertyString)));
    }

    return list.List<Member>();

I’m running out of ideas for this. So if anyone can point us in the right direction I’d appreciate it a lot.

Thanks

  • 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-01T10:46:29+00:00Added an answer on June 1, 2026 at 10:46 am

    This is actually not so much a NHibernate problem, but a general SQL problem.

    Of course it is sorted on the server, but the sum will be calculated for all the records before they can be sorted. You should be able to verify that by using an SQL profiler or by creating an SQL function / procedure that calculates the sum and insert that into your query and then check how often it is called. If you have a table with 500,000+ members it will be called 500,000+ times; there is just no way around it.

    What you could try is this:

    1. Make sure you use an index on Claims.ID (a foreign key does the trick).
    2. Copy&Paste the generated SQL and run it directly on the database and see whether that takes a long time.
    3. If you don’t mind having some form of redundancy you can add new columns for the calculated fields in your Members table and use triggers (insert/delete) on the Claims table to update those columns accordingly.
    4. If you don’t want to use triggers you could also create a scheduled database event to do the calculation. (Of course, that will only be an option if you don’t need real-time data).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have an application that I want to display some data from
I have a Data Grid View inside a control that is displayed in a
I have a data grid that has a checkbox item renderer in a cloumn
I have a data grid where I am displaying my messages. In that if
I have a data grid where in i have to display an image and
I have a WPF app that uses DataGrid to display some data. When I
I have a JavaScript based page where a grid displays all the data for
I have a DataGrid component that displays a few columns of data. It has
I have a Data grid with DatagridComboBoxColumn , and i want to Fire Event
Consider I have a data grid, I need to find the number of rows

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.