Web of Ideas

Developers blog

 

SELECT COUNT(*) in LINQ

13 Dec 2010, 09:56   Subscribe to Richies blog (RSS)

Another short but sweet one:
This is pretty obvious, but I wasn't thinking straight this morning and it took a while.
To do the equivalent of an SQL SELECT COUNT(*) in LINQ, do this:

(from t in myTable where t.MyColumn == myVariable select t).Count();

Obviously, you can put whatever you like in the where clause, or remove it completely.




Comments1
Ratings80
Average rating100%  100%
Posted13 Dec 2010, 09:56

View blog

Richies blog

Previous blog entry: C# double question mark (??) syntax
Next blog entry: Ctrl Alt Del in nested remote desktop

Rate this blog entry

1 (Very poor)  2 (Poor)  3 (Satisfactory)  4 (Good)  5 (Very good)   Enter your name   


Comments


No comments have been made.

Post a comment



Please enter your name to be displayed against the comment