Martin
Martin

Reputation: 425

LINQ and the Count extension method

I have a database table which could contain many records and I'd like to count the current total in the table. I was going to do a simple:

DataContext.Table.Count(c => c.condition);

Until I realized the return type for Count is int. What if the table is to hold more values than can be represented in 32 bits? How can I count them?

Should I be counting them in a different way when we're talking about that kind of scale?

Upvotes: 6

Views: 1005

Answers (2)

Martin
Martin

Reputation: 425

My solution was to use the .LongCount() extension method.

Upvotes: 0

Chris Shaffer
Chris Shaffer

Reputation: 32575

Use LongCount(), same thing but with a 64 bit result.

Upvotes: 10

Related Questions