title: LINQ syntax for CONTAINS method with an inclusive "filter"
body: <p>This may seem a little "much", but this is picking at me!</p>
  
  <p>Envision a form with a CheckBoxList that acts as an inclusive filter for a user. </p>
  
  <p>This user fills out a form, checks off which items in the filter they want, and off they go.</p>
  
  <p>I'm looking for a concise way to write the following LINQ statement:</p>
  
  <p><strong>If NO items are checked, show all results</strong>
  else
  <strong>Show results filtered by user selection</strong></p>
  
  <p>Is it possible (and if so, how) to write this without using a conditional statement that basically is the same query, but without the Contains method?</p>
  
  <p>I tried putting a ternary operator in my Where clause, but the compiler didn't like it at all.</p>
  
  <p>System.Collections.Generic.List catIds = new System.Collections.Generic.List();</p>
  
  <pre><code>              foreach (ListItem lstItemCategory in lstCategories.Items)
                {
                    if (lstItemCategory.Selected)
                    {
                        catIds.Add(Convert.ToInt64(lstItemCategory.Value));
                    }
                }
  
                var qry = from rategroup in rategroups
                          from rate in rategroup.Rates
                          orderby rate.RateClass.Id descending
                          select new
                          {
                              Category = rate.Product.ProductCategories[0].Category.Description,
                              rate.Product.Description,
                              Carrier = rate.CarrierName,
                              Id = rate.Product.ProductCategories[0].Id
                          };
  
  
                this.gvSchedule.DataSource = qry.Where(x =&gt; catIds.Contains(x.Id)).OrderBy(x =&gt; x.Category).ThenBy(x =&gt; x.Carrier).ToArray();
                this.gvSchedule.DataBind();
  </code></pre>