简体   繁体   English

NHibernate QueryOver别名问题

[英]NHibernate QueryOver Alias Issue

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. 我在Visual Web Developer 2010 Express的.Net 4目标项目中使用NuGet的最新版NHibernate(3.3.1.4000)。

When I attempt to follow examples I've seen for defining aliases, I get an exception when setting them up using lambdas (see screenshot). 当我尝试按照我看到的用于定义别名的示例时,在使用lambdas设置它们时会出现异常(参见屏幕截图)。

显示错误'无法将lambda表达式转换为键入'string'...

As you can see I'm getting the error Cannot convert lambda expression to type 'string' because it is not a delegate type . 正如您所看到的,我收到错误Cannot convert lambda expression to type 'string' because it is not a delegate type

I have references to the LINQ namespaces in the top of my code: 我在代码顶部引用了LINQ命名空间:

using System.Linq;
using System.Linq.Expressions;

Any thoughts on what might be causing the problem? 有关可能导致问题的原因的任何想法?

In order to use a variable like role in an expression, you have to define it first, like so... 为了使用一个变量一样role在表达式中,你必须先定义它,像这样......

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>(...) has four overloads: ISession.QueryOver<T>(...)有四个重载:

  • .QueryOver<T>()
  • .QueryOver<T>(Expression<Func<T>> alias)
  • .QueryOver<T>(string entityName)
  • .QueryOver<T>(string entityName, Expression<Func<T>> alias)

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. 显然是因为它无法弄清楚是什么role ,它假设您正在尝试使用.QueryOver<T>(string entityName)重载,因此“无法转换...以键入'字符串'”错误消息。

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

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