In clause in lambda expression

If you have a set of values in an array, then you can use:

.Where(x => charids.Contains(x.Attribute("id").Value)

You can do something like this:

var ids = new []{"id1","id2", ... };
var Charts = chartGroup.Descendants("charts")
                       .Elements("chart")
                .Where(x =>  ids.Contains(x.Attribute("id").Value))
                .Select(x => x.Attribute("name").Value).ToList();

You can use Contains method of IEnumerable:

var ids = new[]{"1", "2"};
Where(x=>ids.Contains(x.Attribute("id").Value));

update:

moreover, this code will transfer in 'in' statement in SQL for IQueryable.

Tags:

C#

Linq

Lambda