与桌子不同

时间:2010-05-10 19:38:56

标签: nhibernate

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>();

2 个答案:

答案 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();