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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:30:25+00:00 2026-05-12T05:30:25+00:00

I am using ASP.NET-MVC and nHibernate for the first time. Great tools, but big

  • 0

I am using ASP.NET-MVC and nHibernate for the first time. Great tools, but big learning curve!

I have a list view of objects that are quite large (each has about 60 properties). In the list view I am only using about 10 of these properties. Performance is not too bad, but it seems a waste to fully hydrate these objects. What is the recommended practice?

I tried using HQL to select fewer properties, but it seems like it won’t partially hydrate an object. I also tried making property on the main object that was a header class with the list view properties, but I couldn’t seem to get it mapped properly. I think this should be easy but I’ve really been struggling with it.

EDIT:
I kept coming back to this because I knew Anton had given me the answer and I just couldn’t see it.

There are three things you need to do:

  1. Make an object with the properties you want.
  2. Make a mapping file to import this object.

    <hibernate-mapping
    xmlns=”urn:nhibernate-mapping-2.2″
    namespace=”Core.Entities”
    assembly=”Core”
    default-access=”property”>
    <import class=”RequestHeader” />
    </hibernate-mapping>

  3. If you are using HQL, your object must contain a constructor with all the properties, in the same order, as your select new statement. If you use the Criteria API, you don’t need to do this.

    public IList<RequestHeader> ListAll()
    {
        using (ISession session = GetSession())
        {
            using (ITransaction tx = session.BeginTransaction())
            {
                IList<RequestHeader> results = session.CreateCriteria(typeof (Request), "r")
                    .CreateCriteria("Requestor", "req", JoinType.InnerJoin)
                    .CreateCriteria("r.Grant", "g", JoinType.InnerJoin)
                    .SetProjection(Projections.ProjectionList()
                        .Add(Projections.Property("r.Id"), "Id")
                        .Add(Projections.Property("r.Status"), "Status")
                        .Add(Projections.Property("r.SubmissionDate"), "SubmissionDate")
                        .Add(Projections.Property("req.Name"), "Requestor")
                        .Add(Projections.Property("g.Number"), "Number"))
                    .SetResultTransformer(Transformers.AliasToBean(typeof (RequestHeader)))
                    .SetMaxResults(10000)
                    .List<RequestHeader>();
                tx.Commit();
                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-12T05:30:25+00:00Added an answer on May 12, 2026 at 5:30 am

    60 properties is too much. See Component mapping.

    As for selecting a subset of properties, see this: you need a select new HQL construct. Be aware, though, that you need an appropriate constructor and that an object you’ll get cannot be saved back to the DB.

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

Sidebar

Related Questions

I have a ASP.NET MVC application using NHibernate and the application runs fine when
I'm developing an application using asp.net mvc, NHibernate and DDD. I have a service
I am using ASP.NET MVC 2 with nhibernate. I have this Sales class. Sales
I have a ASP.NET MVC 3 application using NHibernate over a PostgreSQL database. There
I'm using S#arpArchitecture (ASP.NET MVC and Fluent NHibernate). I have an entity as follows:
I have about 4-6 years .NET experience. Primarly using ASP.NET MVC/Nhibernate/Castle Windsor/MSpec/etc in visual
I have an asp.net-mvc website and i am using ninject for IOC and nhibernate
In my asp.net mvc application I'm using nhibernate 3.2 as ORM. I have catalogue
I'm using ASP.NET MVC + NHibernate + Fluent NHibernate and having a problem with
I'm using ASP.Net MVC (still 1.0 for now) with Castle ActiveRecord and NHibernate.Linq. All

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.