有没有人使用Linq到NHibernate接收到“Unhandled Expression Type:1004”?

时间:2009-09-16 13:24:42

标签: linq nhibernate linq-to-nhibernate

我有一个传递给NHibernate的linq查询,Linq2NHibernate将解析它并返回给我填充的实体。

string firstName = "Ryan";
Store store = _repository.Query<Store>().Where(x => x.Employees.Select(y => y.FirstName).Contains(firstName)).FirstOrDefault();

麻烦的部分是 x =&gt; x.Employees.Select(y =&gt; y.FirstName).Contains(firstName)

这应该做的是选择员工名为Ryan的商店。

我在上面的行中收到错误,上面写着“未处理的表达式类型:1004

在我看来,它是Linq2NHibernate的限制,.Select().Contains()无法解析。

有什么想法吗?有没有其他人都收到此错误?我该怎么做才能解决它或解决它?

[编辑]

以下是我最终使用的内容。

string firstName = "Ryan"
Store store = _repository.Query<Store>().Where(x => x.Employees.Any(y => y.FirstName == firstName)).FirstOrDefault();

Linq查询为x => x.Employees.Any(y => y.FirstName == firstName)

1 个答案:

答案 0 :(得分:3)

我没有使用LINQ到NHibernate,但这不是我在其他任何地方编写该查询的方式。尝试:

string firstName = "Ryan";
Store store = _repository.Query<Store>()
                         .Where(s => s.Employees.Any(
                                e => e.FirstName.Equals(
                                     firstName,  StringComparison.WhateverTypeYouNeed))
               ).FirstOrDefault();

如果L2NH不喜欢string.Equals(),请尝试==

相关问题