title: How to apply OData $select after Couchbase IQueryable is executed
body: <p>I’m trying to implement OData functionality in a web api coupled to a Couchbase bucket using the <a href="https://docs.microsoft.com/en-us/odata/webapi/convention-model-builder" rel="nofollow noreferrer">convention model builder</a> for the Entity Data Model (EDM), with endpoints in .NET Core 3.1 and using these packages:</p>
  
  <pre><code>&lt;PackageReference Include="CouchbaseNetClient" Version="2.7.16" /&gt;
  &lt;PackageReference Include="Linq2Couchbase" Version="1.4.2" /&gt;
  &lt;PackageReference Include="Microsoft.AspNetCore.OData" Version="7.4.0-beta" /&gt;
  </code></pre>
  
  <p>In this first version I return an IQueryable linked to a POCO matching the document to list Client documents.</p>
  
  <pre><code>[EnableQuery]
  public IQueryable&lt;Client&gt; Get([FromServices]ICouchbaseService context)
      =&gt; context.BucketContext.Query&lt;Client&gt;();
  </code></pre>
  
  <p>How OData uses the Queryable to apply the select isn’t possible with Couchbase.</p>
  
  <pre><code>// Couchbase.Linq.CouchbaseQueryException: An error occurred executing the N1QL query.  See the inner exception for details.
  //  ---&gt; System.NotImplementedException: The method or operation is not implemented.
  //    at Microsoft.AspNet.OData.Query.Expressions.SelectExpandWrapperConverter.ReadJson(
  //    Couchbase.N1QL.QueryClient.ExecuteQueryAsync[T](IQueryRequest queryRequest, CancellationToken cancellationToken)
  </code></pre>
  
  <p>Here the $select does work, but this has the disadvantage that $top and $skip won't run as LIMIT and OFFSET on the database.</p>
  
  <pre><code>// localhost:5000/odata/Client?$select=Address/Street,Name
  [EnableQuery]
  public Task&lt;IEnumerable&lt;Client&gt;&gt; Get()
  {
      return this.clientRepository.GetAll().ExecuteAsync();
  }
  </code></pre>
  
  <p>Workaround ideas I have, is to apply the $top and $skip myself to the Couchbase query or not use $select at all.</p>
  
  <p>Which is a proper approach to have $select working? i.e. don't apply the $select on the <code>IQueryable</code> but only on the retrieved results afterwards.</p>
  
  <p>Are there any .NET examples where Couchbase and OData are used together?</p>