Hi Roger - thank you for your reply.  :-)

I have only tried to use the Criteria API:

var criteria = session.CreateCriteria(typeof(A)).Restrictions.IdEq
(id);
criteria.SetFetchMode("Manager.BList", FetchMode.Join);
criteria.CreateAlias("Manager.BList","bl");
criteria.SetFetchMode("bl.CList", FetchMode.Join);
criteria.SetFetchMode("bl.DList", FetchMode.Join);
criteria.SetResultTransformer(new DistinctRootEntityResultTransformer
());

return criteria.UniqueResult<A>();

I had an error when I entered my domain in the first post. It looks
like this:

A
|
*
B -* C
|
*
D


So what I am trying to do is load one entity A, including all of its B
entities. B itself has two associations C and D which must also be
loaded.
The loading of C and D is done in separate selects to the database.

I will try to use HQL instead of the criteria API and see how it goes.

Cheers,
Thomas




On 26 Maj, 13:56, Roger Kratz <[email protected]> wrote:
> You want to eager load some entities and their collections using joins on db 
> side?
>
> As you mention, fetchmode.join (or join fetch in hql), should be the way to 
> go.
> SetFetchMode("SomeCollection", FetchMode.Join)
> If you have misspelled "SomeCollection" or not using the mapped prop name, 
> you will not get an exception but the statement is ignored. Maybe that's 
> happened to you?
>
>
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of 
> Thomas Koch
> Sent: den 26 maj 2009 13:40
> To: nhusers
> Subject: [nhusers] Help with optimizing loading of associations
>
> Hello everyone.
>
> I want to optimize the loading of data in my domain model.
>
> In the past I have used MultiCriteria to load data from different
> tables "in one go" to the database.
>
> However, is it possible to use something similar to MultiCriteria to
> have NHibernate load an entity and its association in one go?
>
> For instance, if I have a domain model like this:
>
> A -* B -* C
> |
> *
> D
>
> Translation: Entity A has a collection of B and D, and B in turn has a
> collection of D.
>
> I tried using FetchMode = Join and Fetch for the associations when
> loading A, but the loading still gives rise to separate selects
> against the database (at least according to Ayendes NHprofiler).
>
> In theory I could use MultiCriteria to load the data of A, B, C and D
> as in one go, but as I understand it the instances thus loaded will
> not be "wired together". So even though all the Bs of A was loaded,
> doing A.Bs will still cause the B's to be loaded.
>
> Does anyone know if its possible to achieve something similar to the
> MultiCriteria where NHibernate is still wiring the entities together?
>
> Regards
> Thomas- Skjul tekst i anførselstegn -
>
> - Vis tekst i anførselstegn -
--~--~---------~--~----~------------~-------~--~----~
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