We've recently upgraded one of our projects to NH 2.1, and would like
to use NHibernate.Linq for as much of our querying as possible.
We have several queries of the following form:
session.CreateCriteria(typeof(Parent))
.CreateCriteria("Children")
.Add(Restrictions.Eq("PropertyOfChild", someValue))
We are using CreateCritera calls (sometimes more than one) to query
across an entity's relationships. This works very well when the
properties are one-to-many or many-to-many relationships. The SQL this
generates (as seen through NHProf) is almost identical to the SQL I
would write by hand. It does an inner join across each relationship,
and then filters the results in the where clause. Simple as cake.
There appears to be no way to get NHibernate.Linq to do this. I've
tried all of the following:
/* Works, but generates a subquery. This quickly gets out of control
with multiple relationships, or when querying anything beyond direct
children (e.g., grandchildren). */
from parent in session.Linq<Parent>()
where parent.Children.Any(c => c.PropertyOfChild == someValue)
select parent;
/* Does an inner join to get to Children, but the joined table isn't
used to filter the results. Instead, a subquery is still generated. */
from parent in session.Linq<Parent>().Expand("Children")
where parent.Children.Any(c => c.PropertyOfChild == someValue)
select parent;
Am I missing something, or is there just no way to do this using the
current iteration of NHibernate.Linq?
-Nick
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---