Gerard
Gerard

Reputation: 1859

NHibernate 3.1 Query equals

I just updated from NHibernate 2.1 to NHibernate 3.1. I found out that the equals operator for the use of Linq was not implemented for other types then string.
I found an article on the internet to solve this problem. This works fine for the basic types but now I want to compare a custom entities and I can't get it to work.

I tried some implementations but none work:

ReflectionHelper.GetMethodDefinition<CustomEntity>(x => x.Equals(<CustomEntity>(0)))  
ReflectionHelper.GetMethodDefinition<CustomEntity>(x => x.Equals(typeof(CustomEntity))

The query I want to execute is as follows:

Session.Query<SomeEntity>().Where(x => x.CustomEntity.Equals(CustomEntity);

How can I extend the equals to allow this and not get an NotSupportedException?

Upvotes: 5

Views: 1184

Answers (1)

Andrey S
Andrey S

Reputation: 71

.Equals method cannot be translated to SQL which is done by the system when you execute Query<>() method. Try using equation like this:

Session.Query<SomeEntity>().Where(x => x.CustomEntity.Id == CustomEntity.Id);

Upvotes: 3

Related Questions