linq select from database where ID in an ArrayList
If it's actually in an ArrayList
, you should create a List<T>
or array first. Then you can use Contains
:
// Use the appropriate type, of course.
var ids = arraylist.Cast<string>().ToList();
var tmp = users.Select(a => ids.Contains(a.UserID));
While using Contains
on the plain ArrayList
may well compile, I would expect it to fail at execution time, assuming users
is an IQueryable<>
.
List<long> list =new List<long>();
var selected = from n in users where list.Contains(n.ID) select n ;
OR
var selected = users.Where(a=> list.Contains(a.ID)).ToList();