tags:

views:

34

answers:

2

ICriteria crit = session.CreateCriteria();

                foreach (ICriteriaItem<object> param in filters)
                {
                    crit.Add(Expression.Eq(param.PropertyName, param.FilterValue));
                }

                crit.SetProjection(Projections.Distinct(Projections.ProjectionList()));

-- disctinct not working can you please help me

                crit.AddOrder(new Order(sortField, sortOrderAscending));

                crit.SetFirstResult(pageNumber * pageSize);

                crit.SetMaxResults(pageSize);

                transaction.Commit();

                return crit.List<IHCOSpendTable>();
+1  A: 

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")
));
dotjoe
when i did this i am getting exception Unable to perform find[SQL: SQL not available]
bharat
does it work without the paging? what is the generated sql?
dotjoe
Yes its working after i made small change how to add the where condition for "sortField" != null or empty
bharat
crit.Add(Expression.IsNotNull(sortField));but i am still getting the empty once
bharat
working after i add thiscrit.Add(Restrictions.Not(Restrictions.Eq(sortField, string.Empty)));
bharat
A: 

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

bharat