Hi,

Let's assume I have the following model :

Country => Client => Orders => OrderLines

For some reasons, I need to load all the clients from a Country and do
some calculations on the Orders and OrderLines, which result in N*N+1
query by default.

I know a few ways to optimize that but none is optimal :

1) eager load Orders and OrderLines
Working, but it results in a cartesian product with a lot of
duplicates returned => my DBA is unhappy !
Is there a way to do that with 2 SELECT queries instead of a 2 outer-
joins?

2) setting a batch-size for the Orders and OrderLines collections.
Drastically reduce the number of queries. However, I don't want to
batch in other parts of the application and I can't find a way to set
the batch on a per session basis. Is there a way to do that?


I also tried something like that (using NH.Linq) to prefetch the data
but it still result in the N*N+1 :

var clients = clientRepo.Query(x => x.Country = "USA");
var orders = orderRepo.Query(x => x.Client.Country = "USA");
var orderLines = orderLineRepo.Query(x => x.Order.Client.Country =
"USA");


Any suggestions?
Isn't there a way to tell nhibernate to initialize all the collections
of a certain type at once?

Many Thanks,

Julien

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to