LINQ: How to test if value is contained in set

c#, linq

Solution

Something like this should work for you:

var listOfConditions = new List<int>{50,60,70};
var tempTable = (from p in dc.Live_Diffs
                             where listOfConditions.Contains(p.RowNum)
                             select new CustomResult
                             {   RowNum = p.RowNum ,
                                 ED1 = p.ED1,
                                 ED2 = p.ED2,
                                 ED3 = p.ED3,
                                 ED4 = p.ED4,
                                 ED5 = p.ED5,
                                 ED6 = p.ED6,
                                 ED7 = p.ED7,
                                 ED8 = p.ED8
                             }).ToList();

Problem

This is probably a pretty simple LINQ question. I'm using LINQ to SQL and pulling a dataset. My current code is this: ``` var tempTable = (from p in dc.Live_Diffs where p.RowNum = 50 select new CustomResult { RowNum = p.RowNum, ED1 = p.ED1, ED2 = p.ED2, ED3 = p.ED3, ED4 = p.ED4, ED5 = p.ED5, ED6 = p.ED6, ED7 = p.ED7, ED8 = p.ED8 }).ToList(); ``` How I can specify a where condition like the following: `"where p.RowNum is in the set: {50,60,70}"`. I have a list or doubles, and I am hoping to avoid using a large number of `"OR"` conditions... Thanks a lot - kcross

Original source