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.  [ 5 posts ] 
Author Message
 Post subject: Count of expressions added to ICriteria
PostPosted: Mon Dec 11, 2006 9:59 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi,

I am dynamically building up an ICriteria object based on user entry in a form and I want to be able to test whether I have added any expressions to the object. ICriteria doesn't seem to expose an item count property though and there doesn't appear to be any way to get access to this information...or maybe I am just not looking in the right place!

Thanks,

Jason


Top
 Profile  
 
 Post subject: Re: Count of expressions added to ICriteria
PostPosted: Wed Jan 24, 2007 11:34 am 
Beginner
Beginner

Joined: Fri Jul 29, 2005 10:34 am
Posts: 25
jason.hill wrote:
Hi,

I am dynamically building up an ICriteria object based on user entry in a form and I want to be able to test whether I have added any expressions to the object. ICriteria doesn't seem to expose an item count property though and there doesn't appear to be any way to get access to this information...or maybe I am just not looking in the right place!



Jason,

I use the following for that case:

Code:
public int Count(ICriteria pCriteria)   {
   if(pCriteria == null) throw new ArgumentNullException("pCriteria");
      pCriteria.SetProjection(Projections.RowCount());
   int count = pCriteria.UniqueResult<int>();
    // Set the original projection list. For normal Tables/Views this is null,   for CustomViews the method GetProjectionList() is used)
    pCriteria.SetProjection(null);


What i could not find (and i think it might be a good idea) is a way of "cloning" the criteria and/or been able to retrieve the current projection list..

So , if you are using SetProjection in your code, the call to Count will destroy it.. (set to null --> no projection).

Sebastian Talamoni


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 24, 2007 4:42 pm 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi Sebastian,

The SetProjection method does not exist on the ICriteria object...are you sure this is an NHibernate feature? I am using v1.0.3.

Besides, it appears from the code that you have provided, that this will return a count of the *results* of the query rather than a count of the number of items in the criteria collection...is that right? I am looking for the latter.

Cheers,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 4:36 am 
Beginner
Beginner

Joined: Fri Jul 29, 2005 10:34 am
Posts: 25
jason.hill wrote:
Hi Sebastian,
The SetProjection method does not exist on the ICriteria object...are you sure this is an NHibernate feature? I am using v1.0.3.

Yes, sorry. This is new in v1.2

jason.hill wrote:
Besides, it appears from the code that you have provided, that this will return a count of the *results* of the query rather than a count of the number of items in the criteria collection...is that right? I am looking for the latter.
Jason


True. I thought you wanted to count the amount of objects return by the criteria. For the latter you wouldn't be able to do it with the interface. You would need to cast to NHibernate.Impl.CriteriaImpl because there the IterateSubCriteria is exposed.

foreach(ICriteria subCriteria in criteria.IterateSubcriteria())

Sebastian Talamoni


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 25, 2007 5:29 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Cool...thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.