我正在尝试执行一个hql查询,该查询返回具有不同属性值的对象列表。以下是我的伪代码:
string hql = @"select distinct m from Merchandise m
where m.Serial is unique"
我在NHibernate上使用Castle ActiveRecord。我花了半天时间解决这个问题,但找不到正确的HQL语法。谁能告诉我该怎么做?
答案 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的属性。