简体   繁体   English

NHibernate 3.1 Query等于

[英]NHibernate 3.1 Query equals

I just updated from NHibernate 2.1 to NHibernate 3.1. 我刚从NHibernate 2.1更新到NHibernate 3.1。 I found out that the equals operator for the use of Linq was not implemented for other types then string. 我发现使用Linq的equals运算符没有实现其他类型的字符串。
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? 如何扩展equals以允许此操作而不是获取NotSupportedException?

.Equals method cannot be translated to SQL which is done by the system when you execute Query<>() method. .Equals方法无法转换为SQL,执行Query <>()方法时由系统完成。 Try using equation like this: 尝试使用如下公式:

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

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

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