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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:52:20+00:00 2026-05-19T23:52:20+00:00

I have a web app that I am building using asp mvc with nhiberante

  • 0

I have a web app that I am building using asp mvc with nhiberante 3.0.
I have the following code for querying my data –

ICriteria rowCount = session.CreateCriteria(typeof(entity1));

rowCount.SetResultTransformer(CriteriaSpecification.DistinctRootEntity)
                .SetProjection(Projections.RowCount());

ICriteria query = session.CreateCriteria(typeof(entity1));

query.SetFetchMode("entity2", FetchMode.Eager);
query.SetResultTransformer(CriteriaSpecification.DistinctRootEntity);
query.SetFirstResult((pageIndex - 1) * pageSize);
query.SetMaxResults(pageSize);

query.Future<entity1>();

return new PagedList<entity1>(query.List<cshearin>(), pageIndex, pageSize, rowCount.List<Int32>().FirstOrDefault());    

Now this is returning the correct data to my view, but the performance is awful. If I do not eager load entity2, the performance is great. The only problem with that is the view is then doing working with the data which I’ve read is not good practice.

Is it ok to have the view do this little bit, or is that bad practice? If it is bad practice, is there a better way that I can build this class for my data access?

Thanks for any thoughts.

EDIT – my mappings are pretty straightforward. Here is a simplified version.
entity1 –

<class name="entity1">
    <id name="entity1_id">
      <generator class="guid.comb"></generator>
    </id>

    <property name="column"></property>
    <property name="column"></property>\

    <bag name="entity2" cascade="all">
      <key column="entity2_fk" />
      <one-to-many class="entity2"/>
    </bag>

  </class>

and entity2 –

<class name="entity2">
    <id name="entity2_id">
      <generator class="guid.comb"></generator>
    </id>

    <many-to-one name="entity1" column="entity2_fk" />

    <property name="columnx"></property>
    <property name="columny"></property>

  </class>

I will also have to look into using projections to pass to my view – that may be a valid answer.

  • 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-19T23:52:20+00:00Added an answer on May 19, 2026 at 11:52 pm

    You should find the reason of bad performance. Use a tool like Profiler (Sql Server) to see the queries generated by NH, or let NH write it to the console (show_sql) or log.

    You may:

    • need an index on the foreign key to get entity2
    • make use of batch-size to get entity2 in batches instead one by one.
    • order by creation date to read newest data first, it may already be in the cache of the DBMS.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a web app using EF Code First and ASP.NET MVC. I have
I have an ASP.NET Web Forms app that I am building and running against
I am building an asp.net MVC2 web app using StructureMap. I have created a
To learn ASP.net I started building a todo web app(web forms not MVC), this
I'm building a web app that many people will be using at the same
I'm building an web app that uses this code to search for addresses: http://code.google.com/intl/en/apis/maps/documentation/javascript/examples/places-autocomplete.html
I'm thinking of building a small web app using the MVC framework as a
HI, using vs2008 and building a web app. On a asp page called blackjack.aspx,
I am building a windows explorer app for the web using ASP.NET/C# 3.5. I
I'm building a small web application with ASP.NET MVC 2, using db4o as a

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.