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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:17:45+00:00 2026-05-14T21:17:45+00:00

I am using NHibernate 2.0.1 and .NET I am facing issues with Lazy loading

  • 0

I am using NHibernate 2.0.1 and .NET
I am facing issues with Lazy loading an association

I have a BusinessObject class that has associations to other BusinessObject in it, and it can go deeper.

The following function is in the BusinessObject to read the values of a collection in the BusinessObject.

    public virtual object GetFieldValue(string fieldName)
    {
        var fieldItems = fieldName.Split(AppConstants.DotChar);
        var objectToRead = this;
        for (var i = 0; i < fieldItems.Length - 1; i++)
        {
            objectToRead = (BusinessObject) objectToRead.GetFieldValue(fieldItems[i]);
        }
        //if (objectToRead._data == null) return objectToRead.SystemId + " Error: _data was null";
        return objectToRead.FieldValue(fieldName.LastItem());
    }  

The FieldValue function is described below

    private object FieldValue(string fieldName)
    {
        return _data.Contains(fieldName) ? _data[fieldName] : null;
    }

The BusinessObject has a dictionary_data which stores the field values.

Assume the fieldName is BusinessDriver.Description and the BusinessObject which has this field is StrategyBusinessDriver

This code breaks down the field name into two – BusinessDriver & Description.
The first iteration reads the BusinessDriver object from StrategyBusinessDriver.
It is cast into a BusinessObject type so that I can call the GetFieldValue again on it to read the next field i.e Description in the BusinessDriver.

The problem is that when I read the BusinessDriver in the first iteration and cast it, I get the Ids and all other details of the BusinessObject but the field dictionary _data and other collections are not fetched. This should be fetched lazily when I read the _data of the BusinessObject.
However, this does not happen and I get an error that _data is null.

Is there something wrongly coded because of which the collection is not fetched lazily?
Please ask for more clarifications if needed.
Thanks in advance.

UPDATE:
I have some more insight into the problem.
The code to load the fields of the BusinessObject is not lazily loaded if the function is called recursively inside the BusinessObject.
If I move this logic out of the BusinessObject, lazy loading works!
Is there a way for this to work inside the BusinessObject?

UPDATE: Mapping file

    <joined-subclass name="Japt.Core.Domain.Data.BusinessObject, Japt.Core, Version=0.0.1608.0, Culture=neutral, PublicKeyToken=null" table="BusinessObject_BusinessDriverStrategyMap" entity-name="BusinessDriverStrategyMap">
  <key column="SystemId" />
  <dynamic-component name="_data" insert="true" update="true" optimistic-lock="true">
    <many-to-one class="Japt.Core.Domain.Data.BusinessObject, Japt.Core, Version=0.0.1608.0, Culture=neutral, PublicKeyToken=null" name="Strategy" entity-name="Strategy">
      <column name="Strategy" />
    </many-to-one>
    <many-to-one class="Japt.Core.Domain.Data.BusinessObject, Japt.Core, Version=0.0.1608.0, Culture=neutral, PublicKeyToken=null" name="BusinessDriver" entity-name="BusinessDriver">
      <column name="BusinessDriver" />
    </many-to-one>
  </dynamic-component>
  <dynamic-component name="_collections" insert="true" update="true" optimistic-lock="true" />
</joined-subclass>
  • 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-14T21:17:46+00:00Added an answer on May 14, 2026 at 9:17 pm

    I think I got the bottom of this issue.
    Since I am trying to read properties lazily of an object within the same object, it is not able to load those properties lazily.
    When I moved that code out using an extension method, the reading of the property was not in the scope of the same object, which is why it worked.

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

Sidebar

Related Questions

Using NHibernate.Mapping.Attributes, I have a entity class with something like: [Class] public class EntityA
I am using ASP.NET MVC2 with NHibernate, but am facing an issue. All calls
i am using Spring.net 1.2 with NHibernate 2.0.1. Within my project i'am facing some
I am trying to develop a .NET Web Project using NHibernate and Spring.NET, but
I am using NHibernate on a new ASP.NET project, and am running into what
I've got an ASP.NET app using NHibernate to transactionally update a few tables upon
I'm using Spring.net with NHiberante (HibernateTemplate) to implement my DAO's. I also have some
Using NHibernate from C# and only HQL (not SQL) in a way that is
I'm using NHibernate 2 and PostgreSQL in my project. SchemaExport class does a great
I recently asked a question about using Fluent NHibernate with .NET 4 - I

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.