如何使用LINQ在Where子句中进行NHibernate子查询? [英] How to a NHibernate subquery in Where clause with LINQ?
问题描述
我试图在where子句中编写一个相关子查询,如下所示:
I'm trying to write a correlated subquery in the where clause like this:
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;
预期的SQL输出与此关于SO的未回答的问题非常相似.
我认为Linq语句本身很好,因为我可以使它在我正在制作原型的LinqPad中运行.但是NHibernate向我抛出了这些神秘的错误:
I think the Linq statement itself is fine because I can get it to run in LinqPad where I was prototyping. But NHibernate throws me these mysterious errors:
错误NHibernate.Hql.Parser [[null)]-NoViableAltException(86 @ [])
ERROR NHibernate.Hql.Parser [(null)] - NoViableAltException(86@[])
错误NHibernate.Hql.Parser [[null)]-MismatchedTreeNodeException(72!= 3)
ERROR NHibernate.Hql.Parser [(null)] - MismatchedTreeNodeException(72!=3)
这是NHibernate LINQ提供程序不支持的方案吗?关于如何重组查询以解决该问题的任何想法?
Is this an unsupported scenario with the NHibernate LINQ provider? Any ideas on how I might be able to restructure this query to get around it?
推荐答案
在解析查询的true == ...
部分时可能会遇到一些麻烦.
It is probably having some trouble parsing the true == ...
portion of the query.
可能想尝试一下,
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;
这篇关于如何使用LINQ在Where子句中进行NHibernate子查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!