使用Criteria API从NHibernate获取不同的结果集? [英] Get Distinct result set from NHibernate using Criteria API?

查看:63
本文介绍了使用Criteria API从NHibernate获取不同的结果集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用NHibernate中的Criteria API获得不同的结果.我知道可以使用HQL做到这一点,但是我更喜欢使用Criteria API进行此操作,因为我的应用程序的其余部分仅使用此方法编写.我找到了该论坛帖子,但未能将其发布到工作.条件API是否有办法获取不同的结果集?

I'm trying to get distinct results using the Criteria API in NHibernate. I know this is possible using HQL, but I would prefer to do this using the Criteria API, because the rest of my app is written using only this method. I found this forum post, but haven't been able to get it to work. Is there a way with the criteria API to get distinct result sets?

在执行此操作时,我还想排除主键列(这也是一个标识),并获取其余的不同记录.有没有办法做到这一点?实际上,不同的记录返回的重复项是因为主键对于每一行都是唯一的,但是所有其他字段都是相同的.

In doing this, I also wanted to exclude the Primary Key column, which is also an identity, and get the remaining distinct records. Is there a way to do this? As it is, the distinct records are returning duplicates because the primary key is unique for each row, but all other fields are the same.

推荐答案

目前无法查看论坛帖子(链接断开?),所以也许这不是答案,但是您可以添加DistinctRootEntityResultTransformer:

Cannot see the forum post at this moment (broken link?), so maybe this is not the answer, but you can add a DistinctRootEntityResultTransformer:

session.CreateCriteria(typeof(Product)
    .Add(...)
    .SetResultTransformer(new DistinctEntityRootTransformer())

这篇关于使用Criteria API从NHibernate获取不同的结果集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆