Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq query to get count

Tags:

linq

id | IsEnquiry  | 
=================
1      true
2      false
3      false
4      true

How can I get the count of id where IsEnquiry=true by using a Linq Query

Pls Help me to write the query.

Thanks, Bharath

like image 322
user735627 Avatar asked May 07 '11 05:05

user735627


People also ask

How to find count in Linq?

In LINQ, you can count the total number of elements present in the given sequence by using the Count Method. This method returns the total number of elements present in the given sequence.

How do you write a count query in Linq?

Count() methodIEnumerable<string> strings = new List<string> { "first", "then", "and then", "finally" }; // Will return 4 int result = strings. Count(); NOTE: The Count() LINQ method (an extension method to IEnumerable<T> ) is slightly different from the Count property on List<T> .

How do you count in IQueryable?

Please use the Count() method. IQueryable<People> list = repository. FindAllPeople; int cnt = list. Count();

What is aggregate in Linq C#?

In LINQ, aggregation functions are those functions which are used to calculate a single value from the collection of the values.


2 Answers

int count = (from row in db.Table
             where row.IsEnquiry == true
             select row).Count();
like image 110
Jared Harding Avatar answered Sep 19 '22 15:09

Jared Harding


try this

var count = db.Table.Where(x=>x.IsEnquiry).Count()
like image 30
Maged Samaan Avatar answered Sep 18 '22 15:09

Maged Samaan