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

时间:2009-12-16 13:05:28

标签: nhibernate hql castle-activerecord

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

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

我在NHibernate上使用Castle ActiveRecord。我花了半天时间解决这个问题,但找不到正确的HQL语法。谁能告诉我该怎么做?

1 个答案:

答案 0 :(得分:2)

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

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

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