NHibernate QueryOver别名问题 [英] NHibernate QueryOver Alias Issue
问题描述
我正在Visual Web Developer 2010 Express的.Net 4目标项目中使用NuGet的最新版本NHibernate(3.3.1.4000).
I'm using the latest version of NHibernate (3.3.1.4000) from NuGet in .Net 4 targeted project in Visual Web Developer 2010 Express.
当我尝试遵循我看到的用于定义别名的示例时,使用lambda设置它们时会出现异常(请参见屏幕截图).
When I attempt to follow examples I've seen for defining aliases, I get an exception when setting them up using lambdas (see screenshot).
如您所见,我收到错误Cannot convert lambda expression to type 'string' because it is not a delegate type
.
As you can see I'm getting the error Cannot convert lambda expression to type 'string' because it is not a delegate type
.
我在代码顶部引用了LINQ命名空间:
I have references to the LINQ namespaces in the top of my code:
using System.Linq;
using System.Linq.Expressions;
对可能导致问题的原因有什么想法?
Any thoughts on what might be causing the problem?
推荐答案
要在表达式中使用像role
这样的变量,就必须像这样先定义它...
In order to use a variable like role
in an expression, you have to define it first, like so...
Role roleAlias = null; // <-- these two lines are missing from your code.
Person personAlias = null;
var x = session.QueryOver<Role>(() => roleAlias)
.JoinAlias(r => r.People, () => personAlias)
// ...
ISession.QueryOver<T>(...)
具有四个重载:
-
.QueryOver<T>()
-
.QueryOver<T>(Expression<Func<T>> alias)
-
.QueryOver<T>(string entityName)
-
.QueryOver<T>(string entityName, Expression<Func<T>> alias)
.QueryOver<T>()
.QueryOver<T>(Expression<Func<T>> alias)
.QueryOver<T>(string entityName)
.QueryOver<T>(string entityName, Expression<Func<T>> alias)
显然,因为它无法弄清role
是什么,所以假设您正在尝试使用.QueryOver<T>(string entityName)
重载,因此出现了无法转换...键入'字符串'"错误消息.
Apparently because it can't figure out what role
is, it's assuming you're trying to use the .QueryOver<T>(string entityName)
overload, hence the "Cannot convert ... to type 'string'" error message.
这篇关于NHibernate QueryOver别名问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!