Where IN clause in LINQ to Entities query

c# entity-framework sql

Question

Possible Duplicates:
Linq to Entities - Sql “IN” clause
How to implement SQL “in” in Entity framework 4.0

how can I add WHERE IN statement like...

SELECT * FROM myTable WHERE ID IN (1,2,3,4,5)

in entity framework

1
16
5/23/2017 10:30:46 AM

Accepted Answer

Use Contains:

int[] ids = { 1, 2, 3, 4, 5};

var query = db.myTable.Where(item => ids.Contains(item.ID));

or in query syntax:

int[] ids = { 1, 2, 3, 4, 5};

var query = from item in db.myTable
            where ids.Contains(item.ID)
            select item;
66
8/16/2010 8:51:51 AM

Popular Answer

I think answer lies somewhere along these lines...

Array a = {1,2,3,4,5}

...WHERE a.Contains(ID)


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow