Reputation: 9738
I want to provide 2 condition's in the COUNT clause for checking ROLE & USERID.
Here is my code :-
var recordCount = ctx.Cases.Count();
How to give Where condition in Count()?
Upvotes: 22
Views: 35613
Reputation: 782
var recordCount = ctx.Cases.Count(a => a.Role == "admin" && a.Userid="userid");
Upvotes: 6
Reputation: 12524
Just add a predicate to your Count()
expression (and don't forget to include System.Linq
):
var recordCount = ctx.Cases.Count(a => a.Role == "admin");
Upvotes: 41
Reputation: 1646
First give Where and then count.
ctx.Cases.Where(c => your condition).Count();
Upvotes: 4