title: Apply PredicateBuilder to query a single object property of a list of items
body: <p>Given the below sample models, I need to query the ITEMS by properties of its owner.
  This is Entity Frameworks sets, and I want to do this using LINQ.</p>
  
  <pre><code>public class Owner
    {
      public int Id { get; set; }
      public string Name { get; set; }
      //More than 20 other properties
    }
  
    class Item
    {
      public int Id { get; set; }
      public string Description { get; set; }
      public Owner MyOwner { get; set; }
      public int idOwner { get; set; }
      //Several others properties
    }
  </code></pre>
  
  <p>I already have a <a href="http://www.albahari.com/nutshell/predicatebuilder.aspx" rel="nofollow noreferrer">PredicateBuilder</a> with the filter of Owners.</p>
  
  <p>I would like to apply this predicate (it is basically the content for where clause) to the <code>Owner</code> object, in order to get all the <code>Item</code> whose Owner meets the predicate condition.</p>
  
  <p>If the <code>Owner</code> were a list of Owners... I could use <code>.Any(predicate)</code> but its cardinality is 1.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I'm trying to do this to avoid having to get all the <code>Owners</code> that fulfill the predicate conditions and then do a <code>Contains(idOwner)</code>.</p>
  
  <pre><code>db.Items.Where(c =&gt; OwnerIdsCollection.Contains(c.idOwner ?? 0));
  </code></pre>
  
  <p>I have seen the massive SQL CASE it creates under the hood for owners that not even have related <code>Items</code>.</p>
  
  <p><strong>EDIT 2 - Predicate:</strong></p>
  
  <pre><code>public static Expression&lt;Func&lt;Owner, bool&gt;&gt; GetPredicate(OwnerCriteria criteria)
  {
       var predicate = PredicateBuilder.True&lt;Owner&gt;();
  
       if (criteria.Active.HasValue) {
      predicate = predicate.And(p =&gt; p.Active == criteria.Active.Value);
       }
       //Several other criteria checkings as above
  
      return predicate;
  }
  </code></pre>
  
  <p>The criteria are obtained from user filters.
  Then, I normally use it for querying Owners collection doing <code>db.Owners.Where(predicate)</code>;</p>
  
  <p>Now, conceptually, I need to do something like:  <code>db.Items.Where(x =&gt; /*Items filters*/  &amp;&amp;  x.MyOwner.Where(myOwnerPredicate))</code></p>