title: Returning child elements in ASP.NET WebAPI OData
body: <p>I'm using the latest ASP.Net WebAPI Nightly builds (dated 2013-01-16).</p>
  
  <p>I have a simple EF database first model at the moment that has two entities - Patients and Visits.  Each patient can have many visits.</p>
  
  <p>I'd like to be able to query for my list of patients and have the visits entities for each patient returned inline.  I know that WebAPI's OData implementation doesn't yet support $expand.  I'm hoping that just means that optional client-controlled expansion is not supported and that I can force expansion server-side.</p>
  
  <p>At the moment I'm not getting any of the visits inline.</p>
  
  <p>For example, my PatientController's() Get() method looks like</p>
  
  <pre><code>[Queryable(AllowedQueryOptions=AllowedQueryOptions.Supported)]
  public override IQueryable&lt;Patient&gt; Get()
  {
      var query = this.entities.Patients.Include("Visits");
      return query;  
  }
  </code></pre>
  
  <p>I've verified that the query executing against my database does indeed include the visit information.</p>
  
  <p>To use a publicly available OData service as an example, if you use the service at <a href="http://services.odata.org/OData/OData.svc/" rel="noreferrer">http://services.odata.org/OData/OData.svc/</a>, you can get a list of Suppliers.  This is <a href="http://services.odata.org/OData/OData.svc/Suppliers" rel="noreferrer">http://http://services.odata.org/OData/OData.svc/Suppliers</a>.
  You can also ask for a list of suppliers that includes the list of products using <a href="http://services.odata.org/OData/OData.svc/Suppliers?$expand=Products" rel="noreferrer">http://http://services.odata.org/OData/OData.svc/Suppliers?$expand=Products</a></p>
  
  <p>Stepping through the ASP.NET code (via the symbols server) I've got to the System.Web.Http.OData.Formatter.Serialization.ODataEntityTypeSerializer and can see that it's CreatePropertyBag method, which builds up the list of properties to be serialized, just doesn't include the navigation properties, and they don't seem to be enumerated anywhere else apart from being written out as NavigationLinks.</p>
  
  <p>I'm quite new to the ASP.NET world in general and have spent a week or so getting my head around the way things work (particularly with the changes made to OData at the end of 2012 and further changes made so far in 2013).</p>
  
  <p>I suspect that if the ODataEntityTypeSerializer was to be modified (I'm happy to try) to embed this extra information in the appropriate spot (within each navigation link as an nested inline feed as best I can tell) then I'd be set.</p>
  
  <p>Questions:</p>
  
  <ol>
  <li><p>Have I overlooked something obvious and there's a flag I can set to turn on this behaviour?  I can see why, if such a flag exists, it would be off by default (EF lazy loading and this flag wouldn't get on well)</p></li>
  <li><p>If #1 is no, is there some other ODataEntityTypeSerializer that I could use?  If so, how do I switch to it?</p></li>
  <li><p>If #2 is no, any pointers for where I should start writing my own?  Is there a place I can substitute in my own serializer or do I have to maintain my own fork of ASP.NET's Extensions project (as opposed to the Runtime project)</p></li>
  </ol>
  
  <p>Thanks very much!</p>