How to do a count(*) on single table

Posts   
 
    
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 06-Jul-2005 16:59:45   

Hi,

I have a table without relations, so I don't get a collection entity of this table, which means that I can't use the getscalar method.

Should I use the dbcount method?

Could someone please provide me example code to get the integer value for a query like this:

SELECT COUNT(*) FROM Customer WHERE country = "NL"

Thanks in advance.

Gr.,

G.I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 06-Jul-2005 19:10:46   

G.I. wrote:

I have a table without relations, so I don't get a collection entity of this table, which means that I can't use the getscalar method.

Every entity gets a collection class in selfservicing, that doesn't rely on if it has relations or not. You use selfservicing I presume? The collection should be there.

Frans Bouma | Lead developer LLBLGen Pro
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 07-Jul-2005 01:08:34   

DUH...ok, there did I something stupid. Anyway, back to my original question:

I need to use the aggregate function CountRow, and a IPredicate filter, to filter on the country. In the function GetScalar, the only option to use a filter also includes using an Expression, but I don't know what expression to use there then...

Gr.,

G.I.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Jul-2005 09:49:52   

count(*) can be done using GetDbCount(). So you can use that to method, just pass in a FieldCompareValuePredicate which filters on country.

GetScalar's overloads which accept an Expression object, ignore the expression value if it's set to null / Nothing (see reference manual simple_smile ). So if you don't want to apply an expression, just specific null / Nothing.

Frans Bouma | Lead developer LLBLGen Pro
G.I.
User
Posts: 172
Joined: 09-Jun-2005
# Posted on: 07-Jul-2005 17:02:21   

Thanks, I've got it now ... d*mn this product is so great, that I think to difficult to get it simple_smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Jul-2005 18:00:42   

smile

Frans Bouma | Lead developer LLBLGen Pro