Reputation: 359
I want write a LINQ query equivalent to
select * from Users
where Username in ('[email protected]', '[email protected]')
Is it possible to write this in LINQ?
Upvotes: 1
Views: 80
Reputation: 819
Or, you can use a very lazy solution
DbEntities db = new DbEntities();
var users = db.Users.where(u => u.Username == "[email protected]" || u.Username == "[email protected]");
Very lazy (Easily understudy by beginner LINQ developer).
Upvotes: 0
Reputation: 152566
In order to replicate the functionality of IN clauses you have to have (or create) a collection and check whether that collection contains the value you're looking for.
var search = new string[] {"[email protected]", "[email protected]"};
var results = Users.Where(u => search.Contains(u.Username));
Upvotes: 3