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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:59:18+00:00 2026-05-10T17:59:18+00:00

I would like to know if there is a way to disable automatic loading

  • 0

I would like to know if there is a way to disable automatic loading of child records in nHibernate ( for one:many relationships ).

We can easily switch off lazy loading on properties but what I want is to disable any kind of automatic loading ( lazy and non lazy both ). I only want to load data via query ( i.e. HQL or Criteria )

I would still like to define the relationship between parent child records in the mapping file to facilitate HQL and be able to join parent child entities, but I do not want the child records to be loaded as part of the parent record unless a query on the parent record explicitly states that ( via eager fetch, etc ).

Example: Fetching Department record from the database should not fetch all employee records from the database because it may never be needed.

One option here is to set the Employees collection on Department as lazy load. The problem with this approach is that once the object is given to the calling API it can ‘touch’ the lazy load property and that will fetch the entire list from the db.

I tried to use ‘evict’ – to disconnect the object but it does not seem to be working at all times and does not do a deep evict on the object. Plus it abstracts the lazy loaded property type with a proxy class that plays havoc later in the code where we are trying to operate on the object via reflection and it encounters unexpended type on the object.

I am a beginner to nHibernate, any pointers or help would be of great help.

  • 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. 2026-05-10T17:59:19+00:00Added an answer on May 10, 2026 at 5:59 pm

    Given your request, you could simply not map from Department to Employees, nor have an Employees property on your department. This would mean you always have to make a database hit to find the employees of a database.

    Aplogies if these code examples don’t work out of the box, I’m not near a compiler at the moment

    So, your department class might look like:

     public class Department   {       public int Id { get; protected set; }      public string Name { get; set; }      /* Equality and GetHashCode here */  } 

    and your Employee would look like:

     public class Employee  {       public int Id { get; protected set; }      public Name Name { get; set; }      public Department Department { get; set; }      /* Equality and GetHashCode here */  } 

    Any time you wanted to find Employees for a department, you’ve have to call:

    /*...*/ session.CreateCriteria(typeof(Employee))     .Add(Restrictions.Eq('Department', department)     .List<Employee>(); 

    Simply because your spec says ‘Departments have many Employees’, doesn’t mean you have to map it as a bi-directional association. If you can keep your associated uni-directional, you can really get your data-access to fly too.

    Google ‘Domain Driven Design’ Aggregate, or see Page 125 of Eric Evan’s book on Domain Driven Design for more information

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

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I think you need to define a separate class to… May 11, 2026 at 11:07 am
  • added an answer Are you using separate service references or web references for… May 11, 2026 at 11:07 am
  • added an answer Any other way of doing this would just be a… May 11, 2026 at 11:07 am

Related Questions

I would like to know if there is a way to disable automatic loading
I would like to know if there is a simple way to parse HTML
I would like to know if there is some way to share a variable
and I would like to know if there is any way to stop a
I am using a wxGenericDirCtrl, and I would like to know if there is
I would like to know if there is any way to add custom behaviour
I would like to know if there is an easy way to detect if
I would like to know if there is any easy way to print multiple
I would like to know if there are general rules for creating an index
I would like to know if there are any tools that can help me

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.