开发者

hql get objects where certain property is unique

开发者 https://www.devze.com 2022-12-14 16:36 出处:网络
I am trying to perform an hql query which returns a list of objects with distinct property value. Following is my pseudo code:

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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号