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