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.
When I attempt to follow examples I've seen for defining aliases, I get an exception when setting them up using lambdas (see screenshot).
As you can see I'm getting the error 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:
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 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:
.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With