Adding conditions to outer joins with NHibernate ICriteria/QueryOver query

fluent-nhibernatejoin;nhibernatequeryover

Is there a way to specify additional conditions on outer joins in NHibernate when querying using QueryOver or ICriteria?

I need some extra conditions on the outer join-ed table, but NHibernate always adds them to the WHERE clause at the end – which does not get the correct behaviour (see http://weblogs.sqlteam.com/jeffs/archive/2007/05/14/criteria-on-outer-joined-tables.aspx).

I can't seem to find any way to do this using Criteria or the QueryOver syntax…

Thanks

Best Answer

You probably figure out this long time ago. Solution is to add ICriteria parameter in JoinAlias method, like this:

Party aliasParty = null;
Party aliasPartyFrom = null;
var parties = QueryOver.Of<Party>(() => aliasParty)
              .Left.JoinAlias(
                               () => aliasParty.AccountabilitiesFrom, 
                               () => aliasAccFrom, 
                               Restrictions.On(() => aliasAccFrom.TimeTo).IsNull)

I have restriction on aliasAccFrom, where i want that TimeTo is null, in last line of code.