title: How to cast SelectExpandQueryOption to IQueryable<T> when using OData in WebAPI?
body: <p>I have a WebAPI that is written in C# on the top of ASP.NET Core/5 framework.</p>
  <p>I enabled <a href="https://github.com/OData/AspNetCoreOData" rel="nofollow noreferrer">odata</a> for my API. I am trying to manually apply the odata filter, order by clause, select columns and the expands.</p>
  <p>Here is how I am trying to manually build the query using the <code>ODataQueryOptions</code></p>
  <pre><code>protected IQueryable&lt;TModel&gt; BuildQuery(ODataQueryOptions&lt;TModel&gt; queryOptions, ODataQuerySettings settings)
  {
      IQueryable&lt;TModel&gt; query = DbSet;
  
      if (queryOptions.SelectExpand != null)
      {
          var queryable = queryOptions.SelectExpand.ApplyTo(query, settings);
  
          query = queryable.Cast&lt;TModel&gt;(); // this causes an error
      }
  
      if (queryOptions.Filter != null)
      {
          query = queryOptions.Filter.ApplyTo(query, settings) as IQueryable&lt;TModel&gt;;  // this works!
      }
  
      if (queryOptions.OrderBy != null)
      {
          query = queryOptions.OrderBy.ApplyTo(query); // this works!
      }
  
      return query;
  }
  </code></pre>
  <p>Everything above works great up until I try to expand a navigation property. When I do I get the following error</p>
  <pre><code>System.InvalidOperationException: 'No coercion operator is defined between types 'Microsoft.AspNetCore.OData.Query.Wrapper.SelectAllAndExpand`1[MyModel]' and 'MyModel'.'
  </code></pre>
  <p>Is there some sort of mapping that I need to do when defining the <code>IEdmModel</code> to build the navigation relations?</p>
  <p>How can I correctly convert/cast <code>IQueryable&lt;Microsoft.AspNetCore.OData.Query.Wrapper.SelectAllAndExpand&lt;TEntity&gt;&gt;</code> to <code>IQueryable&lt;TEntity&gt;</code>?</p>
  <p>Here is the code behind <a href="https://github.com/OData/AspNetCoreOData/blob/f508cb983c98918dba440d5c4be4b304299834b0/src/Microsoft.AspNetCore.OData/Query/Wrapper/SelectAllAndExpandOfT.cs" rel="nofollow noreferrer">SelectAllAndExpand</a></p>