ICriteria crit = session.CreateCriteria<HCOSpendTable>();
foreach (ICriteriaItem<object> param in filters)
{
crit.Add(Expression.Eq(param.PropertyName, param.FilterValue));
}
crit.SetProjection(Projections.Distinct(Projections.ProjectionList()));
区别不工作。
crit.AddOrder(new Order(sortField, sortOrderAscending));
crit.SetFirstResult(pageNumber * pageSize);
crit.SetMaxResults(pageSize);
transaction.Commit();
return crit.List<IHCOSpendTable>();
答案 0 :(得分:1)
您需要将属性映射添加到ProjectionList()
crit.SetProjection(Projections.Distinct(Projections.ProjectionList()
.Add(Projections.Property("id"), "id")
.Add(Projections.Property("name"), "name")
));
答案 1 :(得分:0)
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”), “名字”))));
criteria.SetResultTransformer(new NHibernate.Transform.AliasToBeanResultTransformer(typeof(Person)));
IList people = criteria.List();