title: How does the compiler know what datatype the lambda expression should be
body: <p>So when using EF Core and you use most of the Linq extensions you actually use <code>System.Linq.Expressions</code> instead of the usual <code>Func</code>.</p>
  
  <p>So lets say you are using <code>FirstOrDefault</code> on a <code>DbSet</code>.</p>
  
  <pre class="lang-cs prettyprint-override"><code>DbContext.Foos.FirstOrDefault(x=&gt; x.Bar == true);
  </code></pre>
  
  <p>When you <code>ctrl</code> + <code>lmb</code> on <code>FirstOrDefault</code> it will show you the following overload:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static TSource FirstOrDefault&lt;TSource&gt;(this IQueryable&lt;TSource&gt; source, Expression&lt;Func&lt;TSource, bool&gt;&gt; predicate)
  </code></pre>
  
  <p>But there is also an overload for <code>Func</code>:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public static TSource FirstOrDefault&lt;TSource&gt;(this IEnumerable&lt;TSource&gt; source, Func&lt;TSource, bool&gt; predicate)
  </code></pre>
  
  <p>When you want to store an expression in a variable you can do something like the following:</p>
  
  <pre class="lang-cs prettyprint-override"><code>Func&lt;Entity, bool&gt; = x =&gt; x.Bar == true;
  </code></pre>
  
  <p>and </p>
  
  <pre class="lang-cs prettyprint-override"><code>Expression&lt;Func&lt;Entity, bool&gt;&gt; = x =&gt; x.Bar == true;
  </code></pre>
  
  <p>So how does the compiler decide which overload should be used while using these extension methods?</p>