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(<CustomEn开发者_运维百科tity>(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?
.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);
精彩评论