MetaGuru
MetaGuru

Reputation: 43813

How would I write LINQ to SQL to select rows where an ID is in an array of integers of unknown size?

Say I want to pass an array of integers into a method that runs some LINQ to SQL, how would I say something like "where SuchID is in array[] select"?

Upvotes: 5

Views: 1490

Answers (1)

jason
jason

Reputation: 241611

Use Contains.

int[] ids = // populate ids
var query = from e in db.SomeTable
            where ids.Contains(e.SuchID)
            select e;

LINQ to SQL will translate this to a WHERE clause using IN.

Upvotes: 10

Related Questions