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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:52:27+00:00 2026-05-28T16:52:27+00:00

I have a nhibernate 3.2 query which returns the first 500 Intervention items (in

  • 0

I have a nhibernate 3.2 query which returns the first 500 Intervention items (in the original query there is a filter)

var (from interv in Session.Query<Intervention>()
                .Fetch(rep => rep.ReponsePointVerification)
                orderby interv.DateModification
                select interv)
                .Take(500)
                .ToList();

Then I iterate on all value and use ReponsePointVerification value.

// a (very) simplified example
foreach (var intervention in listeInterventions)
  {
  foreach (var reponse in intervention.ReponsePointVerification)
    {

    }

  listeInterventionsws.Add(interventionws);
}

This query is optimized but it doesn’t work well because the Take method will take 500 lines and if there are ReponsePointVerification value, I won’t have my 500 Intervention items.

So if I want to make it work, I have 2 methods :

  • remove Take(500) and take only the first 500 interventions (heavy when the database grow)
  • Remove the fetch but if I will have 500 + 1 query.

Does nhibernate have a method to handle that case ?

Regards

Edit

Thank you Diego, it worked.

Well I forgot to mention that I used mapping by code in nh 3.2

The batch size with mapping by code can be configured like this :

Bag(x => x.ReponsePointVerification, map =>
{
  map.Key( k => k.Column( "IdIntervention" ) );
  map.BatchSize(50);
}, rm => rm.OneToMany()); 

cf. http://puredotnetcoder.blogspot.com/2011/07/mapping-conventions-with-mapping-by.html

  • 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-28T16:52:28+00:00Added an answer on May 28, 2026 at 4:52 pm

    Use batch-size on the mapping of the affected collections instead of Fetch.

    It’s a better solution in 90% of the cases.

    (I was going to link to the relevant docs section, but the site is down at the moment)

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

Sidebar

Related Questions

I have a basic NHibernate.Linq query: var items = from item in session.Linq<ObjectType>() where
We have an WCF application which uses NHibernate to query data from the database.
I have an NHibernate query that looks like this: var query = Session.CreateQuery(@ select
I have a linq query that is passed into NHibernate which Linq2NHibernate will parse
I have recently downloaded and installed NHibernate 3.1. There are 2 new DLL's which
I have a hibernate query which returns 10s of thousands of object results. Is
I have a nHibernate query like this ICriteria query = session.CreateCriteria(typeof(MyResult)) .Add(Expression.Eq(ResultTypeId, myResult.ResultTypeId)) Problem
I have an nHibernate query issue that looks quite straight forward, but I can't
My scenario is this: I have a base NHibernate query to run of the
I have a simple Nhibernate Linq query that is returning more results than expected:

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.