title: Why don't ODataQueryOptions work for both sides of a 1..* relationship?
body: <p>I have two tables that are joined by a link table and exposed through OData / Entity Framework:</p>
  
  <ul>
  <li>USERS</li>
  <li>USERGROUP</li>
  </ul>
  
  <p>Using ~/api/Users, the following <code>[USER]</code> API controller action returns results:</p>
  
  <pre><code>    public IEnumerable&lt;USER&gt; Get(ODataQueryOptions&lt;USER&gt; options)
      {
          var unitOfWork = new ATMS.Repository.UnitOfWork(_dbContext);
  
          var users = options.ApplyTo(unitOfWork.Repository&lt;USER&gt;().Queryable
                                                .Include(u =&gt; u.USERGROUPS)
                                                .OrderBy(order =&gt; order.USERNAME))
                                                .Cast&lt;USER&gt;().ToList();
  
          unitOfWork.Save();      // includes Dispose()
  
          return users;
      }
  </code></pre>
  
  <p>I am, however, unable to apply the ODataQueryOptions to the following <code>[USERGROUP]</code> API controller action:</p>
  
  <pre><code>    public IEnumerable&lt;USERGROUP&gt; Get(ODataQueryOptions&lt;USER&gt; options)
      {
          var unitOfWork = new ATMS.Repository.UnitOfWork(_dbContext);
  
          var userGroups = options.ApplyTo(unitOfWork.Repository&lt;USERGROUP&gt;().Queryable
                                  .Include(u =&gt; u.USERS)
                                  .OrderBy(order =&gt; order.GROUPNAME))
                                  .Cast&lt;USERGROUP&gt;().ToList();
  
          unitOfWork.Save();      // includes Dispose()
  
          return userGroups.AsQueryable();
      }
  </code></pre>
  
  <p>When I do, I get the following error:  </p>
  
  <blockquote>
    <p>Cannot apply ODataQueryOptions of 'DAL.USER' to IQueryable of
    'DAL.USERGROUP'.</p>
  </blockquote>
  
  <p>Instead, I have to omit the <code>options.ApplyTo(...)</code>:</p>
  
  <pre><code>        var userGroups = unitOfWork.Repository&lt;USERGROUP&gt;()
                                  .Query()
                                  .Include(u =&gt; u.USERS)
                                  .Get()
                                  .OrderBy(order =&gt; order.GROUPNAME);
  </code></pre>
  
  <p>Can someone please explain to me why this is?</p>
  
  <p>Thanks.</p>