title: How to ask for entities having more than 1 nested entity using the generated C# OData client code?
body: <p>I am playing with the TripPin OData demo from <a href="https://github.com/OData/ODataSamples/tree/master/Scenarios/TripPin/src/webapi" rel="nofollow noreferrer">https://github.com/OData/ODataSamples/tree/master/Scenarios/TripPin/src/webapi</a> using the OData C# client code generated by the OData template introduced by the following VS extension: <a href="https://i.stack.imgur.com/FHngA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FHngA.png" alt="enter image description here"></a></p>
  
  <p>The C# code is simple:</p>
  
  <pre><code>var dc = new DefaultContainer(new Uri("http://canws212:23890/"));
  dc.People.AddQueryOption("$expand", "Trips").Where(p =&gt; p.Trips.Any()).First();
  </code></pre>
  
  <p>This returns the first <code>Person</code> entity having any <code>Trip</code> child entities in the <code>Trips</code> property.</p>
  
  <p>But now I wish to get the first <code>Person</code> entity having more than one <code>Trip</code> child:</p>
  
  <pre><code>dc.People.AddQueryOption("$expand", "Trips").Where(p =&gt; p.Trips.Count() &gt; 1).First();
  </code></pre>
  
  <p>This does not work. The request/response as captured by fiddler are:</p>
  
  <p><strong>Request</strong></p>
  
  <pre><code>GET http://canws212:23890/People?$filter=Trips/$count%20gt%201&amp;$top=1&amp;$expand=Trips HTTP/1.1
  OData-Version: 4.0
  OData-MaxVersion: 4.0
  Accept: application/json;odata.metadata=minimal
  Accept-Charset: UTF-8
  User-Agent: Microsoft ADO.NET Data Services
  Host: canws212:23890
  Connection: Keep-Alive
  </code></pre>
  
  <p><strong>Response</strong></p>
  
  <pre><code>HTTP/1.1 400 Bad Request
  Cache-Control: no-cache
  Pragma: no-cache
  Content-Type: application/json; odata.metadata=minimal; charset=utf-8
  Expires: -1
  Server: Microsoft-IIS/8.0
  OData-Version: 4.0
  X-AspNet-Version: 4.0.30319
  X-SourceFiles: =?UTF-8?B?RDpcRGF5Zm9yY2VcU291cmNlXFJlcG9zXE9EYXRhU2FtcGxlc1xTY2VuYXJpb3NcVHJpcFBpblxzcmNcd2ViYXBpXE9EYXRhU2FtcGxlcy5XZWJBcGlTZXJ2aWNlXFBlb3BsZQ==?=
  X-Powered-By: ASP.NET
  Date: Sat, 23 Jul 2016 01:23:41 GMT
  Content-Length: 1604
  
  {
    "error":{
      "code":"","message":"The query specified in the URI is not valid. The method or operation is not implemented.","innererror":{
        "message":"The method or operation is not implemented.","type":"System.NotImplementedException","stacktrace":"   at Microsoft.OData.Core.UriParser.Visitors.QueryNodeVisitor`1.Visit(CountNode nodeIn)\r\n   at Microsoft.OData.Core.UriParser.Semantic.CountNode.Accept[T](QueryNodeVisitor`1 visitor)\r\n   at System.Web.OData.Query.ParameterAliasNodeTranslator.Visit(BinaryOperatorNode nodeIn)\r\n   at Microsoft.OData.Core.UriParser.Semantic.BinaryOperatorNode.Accept[T](QueryNodeVisitor`1 visitor)\r\n   at System.Web.OData.Query.FilterQueryOption.get_FilterClause()\r\n   at System.Web.OData.Query.Validators.FilterQueryValidator.Validate(FilterQueryOption filterQueryOption, ODataValidationSettings settings)\r\n   at System.Web.OData.Query.FilterQueryOption.Validate(ODataValidationSettings validationSettings)\r\n   at System.Web.OData.Query.Validators.ODataQueryValidator.Validate(ODataQueryOptions options, ODataValidationSettings validationSettings)\r\n   at System.Web.OData.Query.ODataQueryOptions.Validate(ODataValidationSettings validationSettings)\r\n   at System.Web.OData.EnableQueryAttribute.ValidateQuery(HttpRequestMessage request, ODataQueryOptions queryOptions)\r\n   at System.Web.OData.EnableQueryAttribute.ExecuteQuery(Object response, HttpRequestMessage request, HttpActionDescriptor actionDescriptor)\r\n   at System.Web.OData.EnableQueryAttribute.OnActionExecuted(HttpActionExecutedContext actionExecutedContext)"
      }
    }
  }
  </code></pre>
  
  <p>What is wrong? Is it a defect of the sample TripPin application or am I doing something wrong? How do I fix it?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I would like the filtration to occur on the database itself. I.e. situation where first all the Person entities are fetched and then filtered out is far from ideal.</p>