简体   繁体   English

NHibernate LINQ查询不支持指定的方法错误

[英]NHibernate LINQ query Specified method is not supported error

I am new to NHibernate and while exploring it I got into trouble with the following query which gives me a "Specified method is not supported." 我是NHibernate的新手,在探索它时,我遇到了以下查询,该查询使我“不支持指定的方法”。 error, any ideas why? 错误,有什么想法吗?

var merchantSite = session.Query<MerchantSite>().FirstOrDefault(x => x.Site.Id == SiteId);
var customers = session.Query<Customer>().Where(x => x.Transaction.Any<Transaction>(y => merchantSite.Transaction.Any<Transaction>(c => c.Id == y.Id))).ToList();

Both MerchantSite and Transaction have a list of objects of type Transaction. MerchantSite和Transaction都具有Transaction类型的对象列表。

There must be someone out there who has been in the similar situation, please share with us your experience, what should we do in this situation? 必须有一个处于类似情况的人,请与我们分享您的经验,在这种情况下我们应该怎么做?

Thanks in advance! 提前致谢!

当您执行ToList调用时,nHibernate正在构建运行查询所需的SQL,并且基本上是在将其转换为单个SQL调用时遇到麻烦。

If x.Site is null, then you'd get "specific method is not supported." 如果x.Site为null,则您将获得“不支持特定方法”。 You could try writing 你可以尝试写

FirstOrDefault(x => x.Site != null && x.Site.Id == SiteId);

or using C# 6 或使用C#6

FirstOrDefault(x => x.Site?.Id == SiteId);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM