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()?
You should be able to do the count on the purch variable: purch. Count(); e.g.
In its simplest form (without any parameters), the Count() method returns an int indicating the number of elements in the source sequence. IEnumerable<string> strings = new List<string> { "first", "then", "and then", "finally" }; // Will return 4 int result = strings. Count();
Language-Integrated Query (LINQ) is the name for a set of technologies based on the integration of query capabilities directly into the C# language. Traditionally, queries against data are expressed as simple strings without type checking at compile time or IntelliSense support.
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");
var recordCount = ctx.Cases.Count(a => a.Role == "admin" && a.Userid="userid");
First give Where and then count.
ctx.Cases.Where(c => your condition).Count();
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