Entity Framework 6 - get deferred IQueryable from navigation collection
<p>I have a simple entity with following relation:</p>

<pre><code>class Foo 
{
    public int BarId { get; set; }
    public virtual Bar { get; set; }
    public boolean Active { get; set; }
    public boolean Condition{ get; set; }
}

class Bar
{
    public virtual ICollection&lt;Foo&gt; Foos { get; set; }
}
</code></pre>

<p>In code I use this navigation collection with a dynamic query and have the problem that the loading is not deferred until the iteration.</p>

<pre><code>public void doSomething(Bar bar, bool condition)
{
    // even with lazy loading all Foo's have been loaded here
    IQueryable&lt;Foo&gt; foos = bar.Foos.AsQueryable().Where(f =&gt; f.Active);

    if (condition)
        foos = foos.Where(f =&gt; f.Condition);

    // I want to defer loading until all filters are applied
    foreach (Foo foo in foos)
    {
        // do something with foo
    }
}
</code></pre>

<p>How do I defer the loading, without using explicit queries using my <code>Bar</code> repository and manually doing a Select with those conditions like:</p>

<pre><code>IRepository&lt;Foo&gt; repoFoo = uow.getRepository&lt;Foo&gt;();
IQueryable&lt;Foo&gt; queryFoo = repoBar.getQuery().Where(f =&gt; f.BarID = bar.ID &amp;&amp; bar.Active)

// check condition
</code></pre>