开发者

hql get objects where certain property is unique

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜