title: OData Expand override Entity Framework includes
body: <p>Consider the following domain model:</p>
  
  <pre><code>public class Employee 
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public int AddressId { get; set; }
      public Address Address { get; set; }
      public ICollection&lt;Message&gt; Messages { get; set; }
  }
  
  public class Address
  {
      public int Id { get; set; }
      public string AddressLine1 { get; set; }
      public string AddressLine2 { get; set; }
      .....
  }
  
  public class Message
  {
      public int Id { get; set; }
      public Message Message { get; set; }
  }
  </code></pre>
  
  <p>We use EF6 code first to create the database for this model. The address data is saved to its own table.
  On top of EF6 we use ASP.NET Web API 2.0 and OData.
  The ODataConventionModelBuilder creates an EntitySet for Employee and a ComplexType for Address.</p>
  
  <p>In order to return an Employee we created the following action:</p>
  
  <pre><code>[EnableQuery]
  public SingleResult&lt;Employee&gt; Get([FromODataUri] int key)
  </code></pre>
  
  <p>In order to always return the Address we use an EF Include on the Address property. So when we use the following url:</p>
  
  <pre><code>/api/Employees(1)
  </code></pre>
  
  <p>The Employee with id 1 will be returned with its Address property filled.</p>
  
  <p>However, when we use <code>$expand</code> to expand the Messages for the use we loose the Address data:</p>
  
  <pre><code>/api/Employee(1)?$expand=Messages
  </code></pre>
  
  <p>Returns an Employee object with Messages expanded, but without the Address data. The <code>EnableQuery</code> attribute applies the expand to our query-able but overwrites the EF Includes that we specified in the API.
  We cannot expand the Address too from the client because Complex types cannot be expanded in OData.
  When we change the Address Odata type to an Entity we need multiple calls to create or update an Employee. One call to an Address controler which handles create/update for addresses and one call to the Employee controller to handle create/update for employees.</p>
  
  <p><strong>So my question</strong>: Is it possible to preserve the Address include without specifying it from the client?</p>