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

查看:21
本文介绍了使用 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天全站免登陆