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

  • Home
  • SEARCH
  • 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 6250299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:23:54+00:00 2026-05-24T13:23:54+00:00

For example, say I have two tables, Product and Order . Product has ID

  • 0

For example, say I have two tables, Product and Order. Product has ID, Name,Description, Cost, and other detailed columns. Order has ID and ProductID columns (assume an order can only contain one product).

When displaying a list of orders in the system, I would like to also display the associated product name without all of the other data (i.e., eagerly load an order and its associated product name, and lazily load all of the other product properties):

SELECT o.ID, o.ProductID, p.Name FROM Order o JOIN Product p ON o.ProductID=p.ID

If I do this with NHibernate, I have two choices: eager loading or lazy loading.

With eager loading, I get something like:

SELECT o.ID, o.ProductID, p.ID, p.Name, p.Description, p.Cost, p.... FROM Order JOIN Product p ON o.ProductID=p.ID

With lazy loading, I get something like:

SELECT o.ID, o.Product ID from Order
....
SELECT p.Name, p.Description, p.Cost, p.... FROM Product p WHERE p.ID=?

Update

Here is a more concrete example of what I am trying to achieve. I am working with an existing DAL and trying to integrate NHibernate. One of the functions of the current DAL is that it allows retrieval of some basic foreign key information as part of the parent record. Let’s say there is a User table and a Region table. Each user has a foreign key to the region in which they reside. When displaying user information in a GUI, the region name should be displayed with the user, but other details about the region are not necessary.

In the current DAL, the User domain object has a member of type ForeignKeyReference<Region>.

public class ForeignKeyReference<T>
{
    public virtual int ForeignKeyID { get; set; }
    public virtual string ForeignNaturalKey { get; set; }
    public virtual T Reference { get; set; }
}

When the User is retrieved from the database, the primary and natural keys for the Region are also retrieved, and the Reference is set to a proxy object. I would like to simplify this with NHibernate, but still maintain this functionality. For example, I would like to remove the ForeignKeyReference<Region> member and just have a Region member which is an NHibernate proxy. On this proxy, I would like to be able to retrieve the ID and the Name without having to hit the database again.

  • 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-24T13:23:55+00:00Added an answer on May 24, 2026 at 1:23 pm

    You can mark a specific column as lazy.
    Ayende wrote about this new feature last year.

    I would suggest you to read the Hibernate documentation about this feature, though:

    Hibernate3 supports the lazy fetching of individual properties. This
    optimization technique is also known as fetch groups. Please note that
    this is mostly a marketing feature; optimizing row reads is much more
    important than optimization of column reads. However, only loading
    some properties of a class could be useful in extreme cases. For
    example, when legacy tables have hundreds of columns and the data
    model cannot be improved.

    The other alternative is to creare your own queries:

    Session.CreateQuery
    

    Have a look at this answer.

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

Sidebar

Related Questions

Say for example, I have the following two tables: TableA { _id } TableB
I have a mysql problem. Let's say for example I have two tables with
As an example: Say there are two tables: Person, and Photo. Each Photo has
I have two websites: http://example.com http://example.com/sub I have a page, let's say: http://example.com/sub/page1 Is
I have two websites, let's say they're example.com and anotherexample.net . On anotherexample.net/page.html ,
Which is your preference? Let's say we have a generic Product table that has
I have two tables like that: Products(productID,categoryID,price) MarginOfProfit(categoryID,rate) Anytime we want to change prices
Say I have two tables, user and comment . They have table definitions that
Lets say I have two tables - child and parent with many-to-one relation. What
Let's say I have two tables: Report Comment And assuming I have a database

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.