count for condition

Posts   
 
    
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 18-May-2007 02:26:51   

How do I use getscalar to count entities for a field vault = "0001"?

I thought I understood, but it wants an expression and I don't know what to put for the expression when I just want to count.

I thought an expression could be a field: customerfields.id for example, but error says: Unable to cast object of type 'SD.LLBLGen.Pro.ORMSupportClasses.EntityField' to type 'SD.LLBLGen.Pro.ORMSupportClasses.IExpression'.

Here is my code: Protected Sub vaultCount_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles vaultCount.Click Dim vaults As New VaultCollection Dim aSort As New SortExpression aSort.Add(New SortClause(VaultFields.Orderx, SortOperator.Ascending)) vaults.GetMulti(Nothing, 0, aSort) For Each vault As VaultEntity In vaults Dim boxs As New StorageCollection Dim vaultCount As Integer = CInt(boxs.GetScalar(StorageFieldIndex.Id, StorageFields.Id, AggregateFunction.Count, StorageFields.Vault = vault.Name)) vault.Count = vaultCount vault.Save() Next Profile.RptParams.Clear() Profile.ReportPath = "/nwmrpts/vaultcount" Response.Redirect("reports.aspx") End Sub

TIA

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 18-May-2007 09:41:22   

Please try the following:

Dim vaultCount As Integer = CInt(boxs.GetScalar(StorageFieldIndex.Id, Nothing, AggregateFunction.Count, StorageFields.Vault = vault.Name))
tvoss avatar
tvoss
User
Posts: 192
Joined: 07-Dec-2003
# Posted on: 18-May-2007 17:53:17   

That worked great! Thanks.