EF SQL changed when passing predicate as Parameter to Where Clause
<p>EF is generating different SQL for the for two similar statements listed below</p>

<pre><code>var test = dbcontext.Persons.GetAll()
                            .Where(c =&gt; c.PersonID == 2)
                            .Select(c =&gt; c.PersonName)
                            .FirstOrDefault();`
</code></pre>

<p>Generated SQL:</p>

<pre><code>SELECT 
    [Limit1].[PersonName ] AS [PersonName ]
FROM 
    (SELECT TOP (1)
         [Extent1].[PersonName ] AS [PersonName ]
     FROM 
         [dbo].[ApplicationRequest] AS [Extent1]
     WHERE 
         [Extent1].[PersonID ] = @p__linq__0) AS [Limit1]',N'@p__linq__0 uniqueidentifier',@p__linq__0= "2"
</code></pre>

<p>I am using the above statements at multiple places with different <code>Where</code> condition; to consolidate logic in one place I am passing the condition as a parameter</p>

<pre><code>Public Void PassPredicate(Func&lt;ApplicationRequest, bool&gt; ReqFunc)
{
    var test = dbcontext.Persons.GetAll()
                                .Where(ReqFunc)
                                .Select(c =&gt; c.PersonName)
                                .FirstOrDefault();
}
</code></pre>

<p>I am calling the function as</p>

<pre><code>PassPredicate(c =&gt; c.PersonID == 2);
</code></pre>

<p>Generated SQL:</p>

<pre><code>SELECT 
    [Extent1].[PersonID] AS [PersonID], 
    [Extent1].[PersonName ] AS [PersonName ], 
    [Extent1].[DOB] AS [Dob], 
    [Extent1].[Height] AS [Height],
    [Extent1].[BirthCity] AS [BirthCity], 
    [Extent1].[Country] AS [Country],
FROM 
    [dbo].[Person] AS [Extent1]
</code></pre>

<p>If you look at the second SQL, it is quite alarming: it is pulling all info (columns and rows). It doesn't have where clause and selecting all columns.</p>

<p>The where condition is being applied after the results were returned from DB.</p>

<p>The only difference in the second statement is I am passing condition as parameter instead of having condition inside where clause.</p>

<p>Can anyone explain why the difference?</p>