How can I use Linq-to-sql to a search like this:
where obj.id equals any of the following {1,2,3,4}
I would guess I could use the in or perhaps contains?
where obj.id in Enumerable.Range( (int) myEnum.Start, (int) myEnum.End) ) ?
How can I use Linq-to-sql to a search like this:
where obj.id equals any of the following {1,2,3,4}
I would guess I could use the in or perhaps contains?
where obj.id in Enumerable.Range( (int) myEnum.Start, (int) myEnum.End) ) ?
You can use .Contains()
, like this:
var list = new List<int> { 1, 2, 3, 5 };
var result = from s in DB.Something
where list.Contains(s.Id)
select s;
This will get translated to a parameterized form of:
WHERE Id IN (1, 2, 3, 5)
var myCustomers = new short[] {1,2,3,4};
var foo = db.Customers.Where(c=> myCustomers.Contains(c.ID));