title: C#, What's the proper syntax for calling an Expression<Func<T-in, T-out>> from within another lambda expression?
body: <p>I'm working in Entity Framework 5 and having problems creating an expression to use inside a method.</p>
  
  <p>I believe the problem is that normally I would call the expression in a lambda expression such as <code>dbContext.Counties.Select(GetLargeCities())</code>, but in the code I am working with, I am projecting the Counties entity into a view model called CountyWithCities. Where I would normally call the expression, I have a singleton <code>c</code> and don't know how to call the expression there.</p>
  
  <p>The reason I want to accomplish this using an expression is because I want the <code>GetCountiesWithCities</code> method to hit the database once, with Entity Framework constructing a complex graph for all the objects in the result.</p>
  
  <p>For some reason the code below is producing the error `The name 'GetLargeCities' does not exist in the current context."</p>
  
  <pre class="lang-cs prettyprint-override"><code>    public class CountyWithCities // this is a view model
      {
          public int CountyID { get; set; }
          public string CountyName { get; set; }
          public IEnumerable&lt;City&gt; Cities { get; set; }
      }
  
      public class City // this is an entity
      {
          public int CityID { get; set; }
          public string CityName { get; set; }
          public int Population { get; set; }
      }
  
      public IEnumerable&lt;CountyWithCities&gt; GetCountiesWithCities(int StateID)
      {
          return dbContext.States
              .Where(s =&gt; s.StateID = StateID)
              .Select(s =&gt; s.Counties)
              .Select(c =&gt; new CountyWithCities
              {
                  CountyID = c.CountyID,
                  CountyName = c.CountyName,
                  Cities = GetLargeCities(c) // How do I call the expression here?
              });
      }
  
      public Expression&lt;Func&lt;County, IEnumerable&lt;City&gt;&gt;&gt; GetLargeCities = county =&gt;
          county.Cities.Where(city =&gt; city.Population &gt; 50000);
  </code></pre>
  
  <p>Thanks!</p>