These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Clearing Projections.ProjectionList()
PostPosted: Wed Mar 05, 2008 5:32 am 
Newbie

Joined: Wed Mar 05, 2008 5:05 am
Posts: 2
Hi

I am currently upgrading our application to NHibernate 1.2 but have encountered a problem that I could do with some help with.

I need to create an ICriteria object and do a RowCount on this (for use with a pager). I then need to add a sort to this ICriteria and select just 12 rows (start position depending on the selected page). The problem I seem to be having is that once I have added Projection.RowCount() to the ICriteria I am unable to remove this RowCount. Does anyone know of a way to remove Projections?

I've been told to use CriteriaTransformer.TransformToRowCount() but CriteriaTransformer seems to be an NHibernate 2.0 feature as I do not have it available.

I have supplied some example code to hopefully help explain what I need.

Code:
ICriteria q             = m_Query;
SearchContainer s = new SearchContainer();

s.Count = (int)q.SetProjection(Projections.ProjectionList().Add(Projections.RowCount())).UniqueResult<int>();

m_Pages           = (int)s.Count;

// I need to clear the ProjectionList at this point

q                 = GetSort(q, this.m_Sort, this.m_SortDir);

q.SetMaxResults(m_VehiclesPerPage);
q.SetFirstResult(m_CurrentStartPage);
m_Vehicles = q.List();


Any assistance would be gratefully appreciated.


Cheers


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 05, 2008 6:39 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You can try:

Code:
Conjunction con = Expression.Conjunction();

... create your criteria with con.Add(...) ...

int count = (int) session.CreateCriteria( type )
                .Add( con )
                .SetProjection( Projections.RowCount() ).UniqueResult();

ICriteria crit = session.CreateCriteria( type )
               .Add( con )
               .AddOrder(...)
...

IList result = crit.List();


_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 07, 2008 7:44 am 
Newbie

Joined: Wed Mar 05, 2008 5:05 am
Posts: 2
Thanks wolli. I've eventually got the chance to try this and it did the trick.

Cheers

Chris


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.