title: Linq - conditional Contains()
body: <p>I have the following method for filtering shops by the criteria specified in parameters:</p>
  
  <pre><code>public int[] GetShopIds(IEnumerable&lt;Guid&gt; OrderCreaatorIds, IEnumerable&lt;Guid&gt; OrderItemCategoryIds, int StatusId)
      {
          var query = from s in _db.Shops
                      join o in _db.Orders on s.Id equals o.ShopId
                      join oi in _db.OrderItems on o.Id equals oi.OrderId
                      where
                      OrderCreaatorIds.Contains(o.CreatorId)
                      &amp;&amp; OrderItemCategoryIds.Contains(oi.CategoryId)
                      &amp;&amp; (int)o.StatusId == StatusId
                      select s.Id;
  
          return query.ToArray();
      }
  </code></pre>
  
  <p>The thing is: <code>OrderCreaatorIds</code>, <code>OrderItemCategoryIds</code> can be <code>null</code> and <code>StatusId</code> can be <code>0</code>. In that case I do not want to have those where clauses, e.g. if <code>OrderCreaatorIds</code> is <code>null</code> then the query should work as follows:</p>
  
  <pre><code>public int[] GetShopIds(IEnumerable&lt;Guid&gt; OrderCreaatorIds, IEnumerable&lt;Guid&gt; OrderItemCategoryIds, int StatusId)
      {
          var query = from s in _db.Shops
                      join o in _db.Orders on s.Id equals o.ShopId
                      join oi in _db.OrderItems on o.Id equals oi.OrderId
                      where
                      OrderItemCategoryIds.Contains(oi.CategoryId)
                      &amp;&amp; (int)o.StatusId == StatusId
                      select s.Id;
  
          return query.ToArray();
      }
  </code></pre>
  
  <p>etc.</p>
  
  <p>Unfortunately <code>where OrderCreaatorIds != null &amp;&amp; OrderCreaatorIds.Contains(o.CreatorId)</code> is not working.</p>