hql 获取某些属性唯一的对象

发布于 2024-08-14 17:58:22 字数 260 浏览 3 评论 0原文

我正在尝试执行 hql 查询,该查询返回具有不同属性值的对象列表。以下是我的伪代码:

string hql = @"select distinct m from Merchandise m
               where m.Serial is unique"

我在 NHibernate 之上使用 Castle ActiveRecord。我在这个问题上花了半天,但找不到正确的 HQL 语法来完成它。有人可以告诉我该怎么做吗?

I am trying to perform an hql query which returns a list of objects with distinct property value. Following is my pseudo code:

string hql = @"select distinct m from Merchandise m
               where m.Serial is unique"

I am using Castle ActiveRecord on top of NHibernate. I have spent half a day on this problem but couldn't find the correct HQL syntax to do it. Can someone tell me what to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

新雨望断虹 2024-08-21 17:58:22

像这样的事情应该可以解决问题:

string hql = @"
     from  Merchandise m
     where not exists (
           from  Merchandise other 
           where m.Serial = other.Serial 
           and   m.Id <> other.Id
           )";

假设商品的 Id 只是一个名为 Id 的属性。

Something like this should do the trick:

string hql = @"
     from  Merchandise m
     where not exists (
           from  Merchandise other 
           where m.Serial = other.Serial 
           and   m.Id <> other.Id
           )";

This assumes the Id of Merchandise is just a property called Id.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文