If I write the code below:
session.Query<Parent>.Count( p => p.Children.Any( c => c.Name == "Child" && c.Age == 10 ) );
The generated SQL is:
select cast(count(*) as INT) as col_0_0_ from "Parent" parent0_
where exists (select children1_.Id from "Child" children1_ where parent0_.Id=children1_.Parent_id and children1_.Name=? and children1_.Age=?)
Due to performance observation in SQL CE 4.0, I would prefer a join, i.e. something like:
select cast(count(*) as INT) as col_0_0_ from "Parent" parent0_
join "Child" children1_ on parent0_.Id = children1_.Parent_id
where children1_.Name=? and children1_.Age=?
I'm sure I'm weak on NHibernate, but after numerous attempts, I still can't figure out how to get it to join the tables without reverting to QueryOver or HQL, but I really like having the dependency defined by IQueryable<T>
. Could someone hint me in the right direction?