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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:50:11+00:00 2026-05-19T01:50:11+00:00

I have a class product with child collection prices: public class Product { private

  • 0

I have a class product with child collection prices:

public class Product
{
    private ICollection<Price> prices;

    protected Product()
    {
        prices = new List<Price>();
    }
}

The NHibernate mapping looks like this

<xml version="1.0" encoding="utf-8">
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
    <class name="Product" table="Product">

    <id name="id" column="ProductId" access="field">
        <generator class="identity"/>
    </id>

            <bag name="prices" access="field" cascade="all-delete-orphan"  lazy="true">
        <key column="ProductId"/>
        <one-to-many class="Product.Price"/>
    </bag>

        </class>

You can see that the prices-collection is lazily loaded.

Products are loaded like this from database:

public ICollection<Product> ListProducts()
    {
        ISession session = GetCurrentSession();

        return session
            .CreateCriteria(typeof(Product))
            .List<Product>();
    }

The function refers on GetCurrentSession(), which has the following content:

protected ISession GetCurrentSession()
    {
         return sessionProvider.GetCurrentSessionFrom(sessionFactoryConfigName);
    }

When I load products, I would expect that on the place of the Price-Collections in the products is a proxy because the prices have lazy-loading = true. But while debugging, with the Visual Studio watch tool I can view the products and can see the prices-collection with full content (Prices with all their properties). Why is this so?

  • 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-19T01:50:12+00:00Added an answer on May 19, 2026 at 1:50 am

    Since you’ve accessed the Prices property while debugging, the proxy will have loaded the products collection …
    That means, you’ve triggered teh lazy loading processs by ‘watching’ the Prices property.

    You can see what happens by configuring nhibernate so that the SQL Statements that are executed, are outputted (show_sql configuration option).

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

Sidebar

Related Questions

Suppose I have public class Product: Entity { public IList<Item> Items { get; set;
Simple question on best practice. Say I have: public class Product { public string
I have the following .Net class: public class Product { public int ID {get;set;}
Hi everyone and couchdb pros, I have a mapping setup like such: class Product(BaseModel):
I have an abstract parent class(Product) and two child classes that inherit from it(Book,Software).
I have the following menu: <ul class=top-menu> <li><a_href=/Products title=Products><span>Products</span></a><ul> <li><a_href=/Products/List title=Product List><span>Product List</span></a></li> </ul>
I have an entity called Product : public abstract class Product : Entity {
I have the following class... public class Product { public int Id { get;
I have common parent\children scenario: public class Order : AdvancedBaseOrder { ICollection<ProducerRelation> producers =
I have three domain class class Stock { Product product } and class Product

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.