title: nested select projection with index in linq using EF Core
body: <p>I just modified a linq query to include an index. The index is necessary to help a client web app manage the items returned (adding, removing, updating, duplicating, etc). That part is working with mockup data on the client side, so it needs the same kind of format structure returned from the server. The index should be sequenced as 0,1,2,..</p>
  
  <p>Below is an example of what I'm trying to do:</p>
  
  <p>Lets say I want to find a list of cities in a country that has states/provinces.</p>
  
  <p>So I have the following two classes:</p>
  
  <pre><code>public class CityItemDTO {
     public int id { get; set; }
     public City item {get; set; }
  }
  
  public class CityDTO {
      public string name {get; set;}
      public string stateName {get; set; }
      public int population {get; set; }
  }
  </code></pre>
  
  <p>I want to add the index along with the list of cities and state properties:</p>
  
  <pre><code>var cities = context.Countries
      .Where(s =&gt; query.Name == s.Name)
      .Select((s,index) =&gt; new CityItemDTO
      {
          id = index,
          item = new CityDTO()
          {
              name = s.name,
              stateName = s.stateName
              population = s.population
          }
      });
  </code></pre>
  
  <p>But I get a weird error:</p>
  
  <blockquote>
    <p>"Could not parse expression 'value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[DataService.Models.Countries]).Where(s => (__query_Name_0 == s.Name)).Select((s, index) => new CityItemDTO() {id = index, item = new CityDTO() {Name = s.Name, StateName = s.StateName, Population = s.Population }})': This overload of the method 'System.Linq.Queryable.Select' is currently not supported."</p>
  </blockquote>
  
  <p>However, the following works if I take the index out:</p>
  
  <pre><code>var cities = context.Countries
      .Where(s =&gt; query.Name == s.Name)
      .Select(s =&gt; new CityDTO
      {
          new CityDTO()
          {
              name = s.name,
              stateName = s.stateName
              population = s.population
          }
      });
  </code></pre>