Distinct from the table
ICriteria crit = session.CreateCriteria<HCOSpendTable>();
foreach (ICriteriaItem<object> param in filters)
{
crit.Add(Ex开发者_Go百科pression.Eq(param.PropertyName, param.FilterValue));
}
crit.SetProjection(Projections.Distinct(Projections.ProjectionList()));
Distinct not working.
crit.AddOrder(new Order(sortField, sortOrderAscending));
crit.SetFirstResult(pageNumber * pageSize);
crit.SetMaxResults(pageSize);
transaction.Commit();
return crit.List<IHCOSpendTable>();
You need to add property maps to the ProjectionList()
crit.SetProjection(Projections.Distinct(Projections.ProjectionList()
.Add(Projections.Property("id"), "id")
.Add(Projections.Property("name"), "name")
));
ICriteria criteria = session.CreateCriteria(typeof(Person)); criteria.SetProjection( Projections.Distinct(Projections.ProjectionList() .Add(Projections.Alias(Projections.Property("FirstName"), "FirstName")) .Add(Projections.Alias(Projections.Property("LastName"), "LastName"))));
criteria.SetResultTransformer( new NHibernate.Transform.AliasToBeanResultTransformer(typeof(Person)));
IList people = criteria.List();
精彩评论