22

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()?

Nicolas Gervais
  • 33,817
  • 13
  • 115
  • 143
Anup
  • 9,396
  • 16
  • 74
  • 138

3 Answers3

41

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");
Alexander Galkin
  • 12,086
  • 12
  • 63
  • 115
6
var recordCount = ctx.Cases.Count(a => a.Role == "admin" && a.Userid="userid");
MaTya
  • 782
  • 6
  • 11
4

First give Where and then count.

ctx.Cases.Where(c => your condition).Count();
AbhinavRanjan
  • 1,638
  • 17
  • 21