score:0

I would use Enumerable<T>.All():

results = results.Where(d => d["FilterIDs" != null &&
    d["FilterIDs"].ToString()
        .Split(',', StringSplitOptions.RemoveEmptyEntries)
        .Select(Int32.Parse)
        .All(f => filterValues.Contains(f)));

score:0

How about this?

results = 
results.Where(
    d => !d.IsNull("FilterIDs") && // Check the row has FilterIds
         d["FilterIDs"]
           .ToString()
           .Split(',') // Tokenise the string
           .Where(s=>!String.IsNullOrEmpty(s))
           .ConvertAll<int>(s => Convert.ToInt32(s))
           .All(i => filterValues.Contains(i) )
      );

score:2

It seems that you have just reversed your Except call - you have used A.Except(B) when you mean B.Except(A).

That said, here's how I would write this:

var query = from row in results
            let filterIds = row["FilterIDs"]
            where filterIds != null
            let numbers = filterIds.ToString()
                                   .Split(',')
                                   .Where(s => !string.IsNullOrEmpty(s))
                                   .Select(int.Parse)
            where !numbers.Except(filterValues).Any()           
            select row;             

Related Articles