title: C# - How to do multiple contains filters on an object list
body: <p>I have a data table that I am trying to implement server side filtering on for the columns.  I am allowing multiple strings to query per column, and am trying to determine the best way to step through all the filters.  Below is an example of the table object, with just 2 of parameters for simplicity sake.</p>
  
  <pre><code>//table models from db
  public class Parts
  {
      public string PartName { get; set; }
      public virtual Series Series { get; set; }
  }
  
  public class Series
  {
      public string SeriesName { get; set; }
  }
  
  //This is what is passed in from the datatable filter query
  public class PartsTable
  {
      public string PartName { get; set; }
  
      public string SeriesName { get; set; }
  }
  
  
  public IEnumerable&lt;Parts&gt; PartsTableSearch(PartsTable table)
  {
      //Queries come in as comma separated string
      var partNameList = table.PartName?.Split(',');
      var seriesNameList = table.SeriesName?.Split(',');
  
      //Gets and generates the list of Parts
      var fullList = GetParts();
  
      if (partNameList != null &amp;&amp; partNameList.Length &gt; 0)
      {        
          foreach (var partName in partNameList)
          {
              fullList = fullList.Where(p =&gt; p.PartName.ToLower().Contains(name.ToLower()));
          }
      }
      if (seriesNameList != null &amp;&amp; seriesNameList.Length &gt; 0)
      {
          foreach (var seriesName in seriesNameList)
          {
              fullList = fullList.Where(p =&gt; p.Series.SeriesName.ToLower().Contains(seriesName.ToLower()));
          }
      }
  
      return fullList;
  }
  </code></pre>
  
  <p>This won't work for what I want because for each parameter (ie. PartName) I need to be able to return all of the objects that have a PartName that contains the search strings in partNameList, then from that result, filter further on the SeriesNames that contain the search strings in seriesNameList, then return the resulting set.  However, the query for partNameList may be blank and only searching on seriesName, and vice versa.  Any suggestions?  I feel like it is an obvious answer that I am simply overlooking, although anything else I've searched for only works for a single query filter.  Thanks in advance.</p>