本文介绍了NHibernate QueryOver关联不包含项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮助我将LINQ表达式转换为Nhibernate QueryOver
could someone help me to translate LINQ expression to Nhibernate QueryOver
from m in messages
where !m.Recipients.Any(rcpt => rcpt.IsDeleted && rcpt.User = user)
我尝试过
var qry = Session.QueryOver<UserMessage>();
qry.Where(m => m.Recipients.Any(r => !r.IsDeleted && r.User == user));
但是得到了
System.Exception:无法识别的方法调用:System.Linq.Enumerable:Boolean Any [TSource](System.Collections.Generic.IEnumerable 1[TSource], System.Func
2 [TSource,System.Boolean]
System.Exception : Unrecognised method call: System.Linq.Enumerable:Boolean Any[TSource](System.Collections.Generic.IEnumerable1[TSource], System.Func
2[TSource,System.Boolean]
推荐答案
我设法做到这一点:
UserMessage messageAlias = null;
var qry = Session.QueryOver<UserMessage>(() => messageAlias);
UserMessageRecipient recipientAlias = null;
var deletedbyUser = QueryOver.Of(() => recipientAlias)
.Select(x => x.Id)
.Where( () => recipientAlias.Message.Id == messageAlias.Id
&& (recipientAlias.Recipient == query.User && recipientAlias.IsDeleted))
.DetachedCriteria;
qry.Where(Subqueries.NotExists(deletedbyUser));
这篇关于NHibernate QueryOver关联不包含项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!