hql获取某些属性是唯一的对象
问题描述:
我想执行一个hql查询,它返回具有不同属性值的对象列表。以下是我的伪代码:hql获取某些属性是唯一的对象
string hql = @"select distinct m from Merchandise m
where m.Serial is unique"
我在NHibernate上使用Castle ActiveRecord。我在这个问题上花了半天的时间,但找不到正确的HQL语法来完成它。有人能告诉我该怎么做吗?
答
像这样的东西应该做的伎俩:
string hql = @"
from Merchandise m
where not exists (
from Merchandise other
where m.Serial = other.Serial
and m.Id <> other.Id
)";
这是假设商品的ID就是所谓的ID的属性。