LINQ where Clause doubt

sss picture sss · Jan 2, 2009 · Viewed 9.5k times · Source

I have tried one where clause in Linq to get details about Users those who are Active and AllowLogin is also true.

So how can I compare the table values (both are boolean values) with true or false?

Answer

Jon Skeet picture Jon Skeet · Jan 2, 2009

Just use something like:

var query = from user in context.Users
            where user.Active && user.AllowLogin
            select user;

Alternatively, you can write the same query without a query expression:

var query = context.Users.Where(user => user.Active && user.AllowLogin);