LINQ flavored IS IN Query

c#, lambda, linq

Solution

`Contains` is the way forward:

var chiLst = new List<string>();
var parRec = Lnq.attlnks.Where(a => chiList.Contains(a.sysid))
                        .Select(a => a.ownerid);

Although you'd be better off with a `HashSet<string>` instead of a list, in terms of performance, given all the contains checks. (That's assuming there will be quite a few entries... for a small number of values, it won't make much difference either way, and a `List<string>` may even be faster.)

Note that the performance aspect is assuming you're using LINQ to Objects for this - if you're using something like LINQ to SQL, it won't matter as the `Contains` check won't be done in-process anyway.

Problem

There are quite a few other questions similiar to this but none of them seem to do what I'm trying to do. I'd like pass in a list of string and query ``` SELECT ownerid where sysid in ('', '', '') -- i.e. List<string> ``` or like ``` var chiLst = new List<string>(); var parRec = Lnq.attlnks.Where(a => a.sysid IN chiList).Select(a => a.ownerid); ``` I've been playing around with a.sysid.Contains() but haven't been able to get anywhere.

Original source

Related problems