title: Adding a custom navigation property to OData Web API Controller
body: <p>I have an OData v3 Web API project.  It uses an Entity Framework Code First model.  </p>
  
  <p>The main class is Coupon.  It has a List.  What this really is, is a 2-element collection of subtypes ItemRequirement and BasketRequirement.  I want to be able to say:</p>
  
  <pre><code>../odata/Coupons(5)/ItemRequirement
  </code></pre>
  
  <p>I can NOT get this to work.</p>
  
  <p>First, in the EF class, I have added ItemRequirement as a [NotMapped] property (as the class already has a collection of the base class as a navigation property, and adding the other two as properties would just generate extraneous table keys and mess up the database unnecessarily.  The Table-Per-Hierarchy in Code First is working great as is).</p>
  
  <p>The ODataConventionModelBuilder() is not picking up ItemRequirement as a navigation property</p>
  
  <p>I attempted to add it:</p>
  
  <pre><code>// GET odata/Coupons(5)/ItemRequirement
  public ItemRequirement GetItemRequirement( [FromODataUri] decimal key)
  {
     return db.Coupons.Where(m =&gt; m.CouponId == key).SelectMany(m =&gt; m.RedemptionPurchaseRequirements).OfType&lt;ItemRequirement&gt;().FirstOrDefault();
  }
  </code></pre>
  
  <p>The URI will NEVER get into this code.  I have found by adding an IODataRoutingConvention implementor that the ODataPath is set to navigation/key/unresolved.</p>
  
  <p>I looked at this solution and it didn't help me, either:</p>
  
  <p><a href="https://stackoverflow.com/questions/23082927/adding-a-custom-query-backed-navigation-property-to-odataconventionmodelbuilder">Adding a custom query backed Navigation Property to ODataConventionModelBuilder</a></p>
  
  <p>I don't know if the problem is the inheritance, the fact that the property is not mapped in EF, or what.</p>
  
  <p>I have also found that this fails with a 404:</p>
  
  <pre><code>oData/PurchaseRequirementsBases(5)/myNamespace.ItemRequirement
  </code></pre>
  
  <p>Just what witchcraft is necessary to abstract the collection away so the OData consumer can see ItemRequirement as a valid property of Coupon?</p>