Vivek Patel
Vivek Patel

Reputation: 359

How to select mutiple rows from Entity using Linq

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

Answers (2)

Sagar Upadhyay
Sagar Upadhyay

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

D Stanley
D Stanley

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

Related Questions