Hi.
How can I execute a criteria to obtain a count of objects, but i don't retrive a collection, i need only count. It is to verify if exist any objects in the association.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If you want to use the "Select Count(...) from ..." SQL syntax then you will need to use a SummaryCriteria. Eg
dim sc as CSummaryCriteria
sc.ClassMap = myClassMap
sc.addSummaryField("myField", SumMethod.Count)
dim cc as CCursor = sc.perform()
dim recordCount as Integer
recordCount = cc.ResultSet.ResultSet.Tables(0).Rows(0).Item(0)
If you are just wanting to know if any records exist, you can use a normal retrieve criteria, and just use a rowlimit of 1. After you do the perform just do a check if records exist in the cursor.
For example
Dim rc as new CRetrieveCriteria
rc.RowLimit = 1
...
dim cc as CCursor = rc.Perform()
if cc.hasElement then
'Records exist
else
'No records
end if
- Richard
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi.
How can I execute a criteria to obtain a count of objects, but i don't retrive a collection, i need only count. It is to verify if exist any objects in the association.
Hi Victor,
If you want to use the "Select Count(...) from ..." SQL syntax then you will need to use a SummaryCriteria. Eg
dim sc as CSummaryCriteria
sc.ClassMap = myClassMap
sc.addSummaryField("myField", SumMethod.Count)
dim cc as CCursor = sc.perform()
dim recordCount as Integer
recordCount = cc.ResultSet.ResultSet.Tables(0).Rows(0).Item(0)
If you are just wanting to know if any records exist, you can use a normal retrieve criteria, and just use a rowlimit of 1. After you do the perform just do a check if records exist in the cursor.
For example
Dim rc as new CRetrieveCriteria
rc.RowLimit = 1
...
dim cc as CCursor = rc.Perform()
if cc.hasElement then
'Records exist
else
'No records
end if
- Richard