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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:41:01+00:00 2026-05-18T02:41:01+00:00

In that simple case: public class Person { public int Id {get;set;} public int

  • 0

In that simple case:

public class Person
{
     public int Id {get;set;}
     public int Name {get;set;}
}
  • I need generate a Grid with paging and ordering
  • My database has about 100k persons

What option has better performance :

1) Get all elemtents in the first time and after take advantage of NHibernate First Level Cache, example:

personRep.FindAll().OrderBy(s =>s.Name).AsPagination(pageNumber,pageSize);

Obs.: AsPagination is a extension method…

2) Get only the actual page from database, example:

   public virtual IList<T> GetPaginedList(int __pageIndex, int __pageSize,out int __total)
    {            
        var _rowCount = Session.CreateCriteria(typeof(T))
            .SetProjection(Projections.RowCount()).FutureValue<Int32>();

        var _results = Session.CreateCriteria(typeof(T))
            .SetFirstResult(__pageIndex * __pageSize)
            .SetMaxResults(__pageSize)
            .Future<T>();

        __total = _rowCount.Value; 
        return _results;
    } 
  • 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-18T02:41:02+00:00Added an answer on May 18, 2026 at 2:41 am

    The 2nd option would be the best fit.

    It is useless to retrieve all instances in one go, when you (the user) perhaps doesn’t even ‘use’ all those instances.

    If the ‘Person’ class is a ‘heavy’ class with lots of associations, it would be even better to create a ‘PersonView’ class, which contains only the properties you want to show in the Grid.

    You don’t have to map that PersonView class, you’ll simply have to ‘import’ it, so that NHibernate knows of its existance.
    Then, you create a query on the Person class, and define that a AliasToBean Transformer has to be used to convert the Person instances to PersonView instances.

    By doing so, NHibernate will be able to generate a query which only retrieves the necessary columns from the DB, and will populate PersonView instances with it.

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

Sidebar

Related Questions

Suppose I have a simple class that Adds: public class Multiply { public int
My logging library has a simple DebugLogger that looks like this: public class DebugLogger
Say we have this hyper simple class hierchy: public class SomeMath { public int
Let's start with a simple test case: import java.lang.reflect.Field; public class Test { private
It's a simple case of a javascript that continuously asks are there yet? Like
I have a Table: public class AppointmentTableModel extends AbstractTableModel { private int columns; private
I have a case where I'm using a macro to generate simple subclasses. I've
Here's my use case : public class User extends Model {} public class TableA
In this opportunity I try to do a simple activity that get a EditText
I have a simple class that has a property called executor in which I'd

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.