Hi I'm having a problem with getting a conditional query to work. I want all projects where project.Parent either is null or if it has a parent then it shouldn't be voided or closed.
My example will NOT bring back any projects where project.Parent == null.
We are using linq-to-nhibernate
var projects = (from project in this.Session.Query<Project>()
where project.IsClosed == false
&& project.IsVoided == false
&& (project.Parent == null
|| (project.Parent.IsVoided == false
&& project.Parent.IsClosed == false))
select project).ToList();
That query won't work because inner joins are generated for the Parent property.
The easiest workaround is doing two queries and joining them client-side: