Lambda expression "IN" operator Exists?

sivaL picture sivaL · Nov 22, 2012 · Viewed 31.8k times · Source

I'm looking for to build the Lambda expression like the below

IQueryable<Object> queryEntity = 
                _db.Projects.Where(Project=>Project.Id.IN(1,2,3,4));

I don't find any IN operator in Lambda expression.

Anybody have suggestions?

Answer

Anders Arpi picture Anders Arpi · Nov 22, 2012

Use IEnumerable.Contains for this.

var idList = new[] { 1, 2, 3, 4 };
IQueryable<Object> queryEntity = 
                _db.Projects.Where(Project => idList.Contains(Project.Id));

You could construct the idList inline of course.