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.
精彩评论