NHibernate QueryOver别名问题
我在Visual Web Developer 2010 Express的.Net 4目标项目中使用NuGet的最新版NHibernate(3.3.1.4000)。
当我尝试按照我看到的用于定义别名的示例时,在使用lambdas设置它们时会出现exception(参见屏幕截图)。
正如您所看到的,我收到错误Cannot convert lambda expression to type 'string' because it is not a delegate type
。
我在代码顶部引用了LINQ命名空间:
using System.Linq; using System.Linq.Expressions;
有什么可能导致问题的想法?
为了在表达式中使用类似变量的变量,您必须首先定义它,就像这样……
Role roleAlias = null; // <-- these two lines are missing from your code. Person personAlias = null; var x = session.QueryOver(() => roleAlias) .JoinAlias(r => r.People, () => personAlias) // ...
ISession.QueryOver
有四个重载:
-
.QueryOver
() -
.QueryOver
(Expression > alias) -
.QueryOver
(string entityName) -
.QueryOver
(string entityName, Expression > alias)
显然是因为它无法弄清楚是什么role
,它假设您正在尝试使用.QueryOver
重载,因此“无法转换…以键入’字符串’”错误消息。