inline response
2010/5/3 Azhar <[email protected]>:
> can anyone help me to create a paginated list with filter and sort
> criteria using CreateMultiCriteria,
> please help me, how to add filters and sort criteria.
> my code is as follows
>
> public IList<T> GetPagedData(int page, int pageSize, out long count)
Have your method take int firstResult and int maxResults instead,
since that is how you use the parameters below. The current names
don't correspond to the usage.
What criteria do you want to add? The method is generic for type T. If
you don't know what the type is, how would you now what criteria to
add?
> {
> try
> {
> IList<T> all = new List<T>();
>
> ISession s = NHibernateSession;
> IList results =
> s.CreateMultiCriteria()
>
> .Add(s.CreateCriteria(typeof(T)).SetFirstResult(page).SetMaxResults(pageSize))
>
> .Add(s.CreateCriteria(typeof(T)).SetProjection(Projections.RowCount()))
> .List();
You need to stick the filters on the "inner" critera objects, so you
need to declare variables for those.
> foreach (Object o in (IList)results[0])
> all.Add((T)o);
>
> count = long.Parse((((IList)results[1])
> [0]).ToString());
Shouldn't count = (long)(((IList)results[0])[0]); work? Avoiding a
string format and parse. Avoid the cast with RowCount64().
> return all;
> }
> catch (Exception ex) { throw new
> Exception("GetPagedData", ex); }
> }
>
/Oskar
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.