title: How to have Entity Framework navigation property query filter in database by default?
body: <p>the dbcontext api seems to set navigation properties to ICollections (for the * ends of associations). The normal way to get queryable objects (like if you wanted a count) seems to be </p>
  
  <pre><code>int count = dbcontext.Entry(entry).Collection(c =&gt; c.navprop).Query().Count();
  </code></pre>
  
  <p>but that's inconvenient if you want to filter in the db often. More importantly, it's also easy to forget. If someone accidentally says </p>
  
  <pre><code>int count = entry.navprop.Count();
  </code></pre>
  
  <p>then it gets all of the data on the server and does the count there, which is slow.</p>
  
  <p>The same thing is true for the EntityCollection type that ObjectContext uses by default. </p>
  
  <pre><code>int count = entry.navprop.CreateSourceQuery().Count();
  </code></pre>
  
  <p>Is there a way to set in the model or somewhere else that the default collection type for a navigation property is an IQueryable or an ObjectQuery or some kind of queryable type?</p>
  
  <p>Note this is only a problem for navigation properties as the actual objectset and dbset items in the context seem to be queryable</p>