How to eager fetch a child collection while joining child collection entities to an association
- by ShaneC
Assuming the following fictional layout
Dealership
  has many Cars
     has a Manufacturer
I want to write a query that says get me a Dealership with a Name of X and also get the Cars collection but use a join against the manufacturer when you do so.  I think this would require usage of ICriteria.  I'm thinking something like this..
var dealershipQuery = Session.CreateCriteria< Dealership>("d")
                             .Add(Restrictions.InsenstiveLike("d.Name", "Foo"))
                             .CreateAlias("d.Cars", "c")
                             .SetFetchMode("d.Cars", FetchMode.Select)
                             .SetFetchMode("c.Manufacturer", FetchMode.Join)
                             .UniqueResult< Dealership>();
But the resulting query looks nothing like I would have expected.  I'm starting to think a DetachedCriteria may be required somewhere but I'm not sure.
Thoughts?