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?
LINQ provides many extension methods for filtering, grouping, sorting and many more which will make developers' lives easy.
The Count() method is an extension method of IEnumerable included in System. Linq. Enumerable class. It can be used with any collection or a custom class that implements IEnumerable interface. All the built-in collections in C#, such as array, ArrayList, List, Dictionary, SortedList, etc.
In LINQ, Method Syntax is used to call the extension methods of the Enumerable or Queryable static classes. It is also known as Method Extension Syntax or Fluent. However, the compiler always converts the query syntax in method syntax at compile time.
Use LongCount(), same thing but with a 64 bit result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With