Eager Loading Using Fluent NHibernate/Nhibernate & Automapping

前端 未结 4 515
萌比男神i
萌比男神i 2020-12-13 19:34

I have a requirement to load a complex object called Node...well its not that complex...it looks like follows:-

A Node has a refere

4条回答
  •  失恋的感觉
    2020-12-13 19:52

    I figure it out myself. The key is to use SetResultTransformer() passing an object of DistinctRootEntityResultTransformer as a parameter. So the query now looks like as follows

    Session.CreateCriteria(typeof (Node))
       .SetFetchMode( "Etype", FetchMode.Join )
       .SetFetchMode( "Etype.Properties", FetchMode.Join )
       .SetFetchMode( "Etype.Properties.ListValues", FetchMode.Join )
       .SetResultTransformer(new DistinctRootEntityResultTransformer());
    

    I found the answer to my questions through these links:

    http://www.mailinglistarchive.com/html/nhusers@googlegroups.com/2010-05/msg00512.html

    http://ayende.com/Blog/archive/2010/01/16/eagerly-loading-entity-associations-efficiently-with-nhibernate.aspx

提交回复
热议问题