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