How is the NHibernate subquery in the Where section with LINQ?

I am trying to write a correlated subquery in a where clause as follows:

var foo = from d in session.Query<Document>()
          where true == 
              ( from a in session.Query<ACLEntry>()
                where a.Id == d.Id || a.Id == null
                select a.Result
              ).FirstOrDefault()
          select d;

The expected SQL output is very similar to this unanswered SO question .

I think the Linq operator itself works fine, because I can get it to work in LinqPad, where I was the prototype. But NHibernate throws me these mysterious errors:

ERROR NHibernate.Hql.Parser [(null)] - NoViableAltException (86 @ [])

ERROR NHibernate.Hql.Parser [(null)] - MismatchedTreeNodeException (72! = 3)

Is this an unsupported NHibernate LINQ provider scenario? Any ideas on how I can restructure this query to get around it?

0
source share
2 answers

:

var foo = from d in session.Query<Document>()
          where (from a in session.Query<ACLEntry>()
                  where a.Id == d.Id || a.Id == null
                  select a.Result
                 ).FirstOrDefault() != null
          select d;

, !

0

, true == ... .

, ,

var foo = from d in session.Query<Document>()
    where (from a in session.Query<ACLEntry>()
           where a.Id == d.Id || a.Id == null
           select a.Result
          ).FirstOrDefault()
    select d;
0

All Articles