NHibernate 3.1 Query等于

Ger*_*ard 5 c# linq nhibernate equals

我刚从NHibernate 2.1更新到NHibernate 3.1.我发现使用Linq的equals运算符没有实现其他类型的字符串.
我在互联网上发现了一篇解决这个问题的文章.这适用于基本类型,但现在我想比较自定义实体,我无法让它工作.

我尝试了一些实现但没有工作:

ReflectionHelper.GetMethodDefinition<CustomEntity>(x => x.Equals(<CustomEntity>(0)))  
ReflectionHelper.GetMethodDefinition<CustomEntity>(x => x.Equals(typeof(CustomEntity))
Run Code Online (Sandbox Code Playgroud)

我想要执行的查询如下:

Session.Query<SomeEntity>().Where(x => x.CustomEntity.Equals(CustomEntity);
Run Code Online (Sandbox Code Playgroud)

如何扩展equals以允许此操作而不是获取NotSupportedException?

小智 3

.Equals 方法无法转换为 SQL,这是在执行 Query<>() 方法时由系统完成的。尝试使用这样的方程:

Session.Query<SomeEntity>().Where(x => x.CustomEntity.Id == CustomEntity.Id);
Run Code Online (Sandbox Code Playgroud)