Reputation: 1900
How can I write LINQ to SQL with COUNT?
Example:
var purch = from purchase in myBlaContext.purchases
select purchase;
How can I get the count here?
Upvotes: 49
Views: 203607
Reputation: 56726
Like that
var purchCount = (from purchase in myBlaContext.purchases select purchase).Count();
or even easier
var purchCount = myBlaContext.purchases.Count();
Upvotes: 91
Reputation: 3442
You should be able to do the count on the purch variable:
purch.Count();
e.g.
var purch = from purchase in myBlaContext.purchases
select purchase;
purch.Count();
Upvotes: 10