I had a table that contained a couple of columns defined in SQL 2005 as tinyint. In SQL, I’d generally write something like:

1
2
3
SELECT COUNT(EmailOptIn)  
FROM Members  
WHERE EmailOptIn = 1

Of course using LINQ there are lots of different ways to option the count. The simplest way is to use a Lambda Expression. Here’s what I came up with in VB.NET:

1
db.Members.Count(Function(p) p.EmailOptIn)

Translated in C#, it would be this:

1
db.Members.Count(p => p.EmailOptIn);

Hope that helps!