title: How do you get a web API odatamodelbuilder to work with EF fluent API mappings
body: <p>I have created a fairly simply domain model using pocos. I have mapped these to an EF DB context using <code>EntityTypeConfiguration&lt;TEnitityType&gt;</code> classes.  This all works fine.</p>
  
  <p>I am now trying to create an OData V4 WebAPI controller endpoint using a <code>ODataConventionModelBuilder</code> and this is where things are coming unstuck.  It all works fine until it encounters an association that is not convention based.  But I cannot find a way to get the <code>ODataBuilder</code> to pick up the mappings from my <code>EntityTypeConfiguration&lt;TEnitityType&gt;</code> classes.</p>
  
  <p>This leaves my with 2 unpalatable options</p>
  
  <ul>
  <li>Decorate my lovely clean pocos with dirty attributes.</li>
  <li>Re-map all the non convention based mappings manually using the <code>ODataBuilder</code></li>
  </ul>
  
  <p>Not sure if code samples will help but here they are anyway, i have simplified the entities for brevity.</p>
  
  <pre><code>var builder = new ODataConventionModelBuilder();
  
              builder.EntitySet&lt;Item&gt;("Items");
              config.MapODataServiceRoute(
                  routeName: "odata",
                  routePrefix: "odata",
                  model: builder.GetEdmModel(),
                  batchHandler: new DefaultODataBatchHandler((GlobalConfiguration.DefaultServer)));
  
   public class Item
      {
          public Int32 Id { get; set; }
  
          public Int16 ItemTypeId { get; set; }                   
  
          public virtual ItemType Type { get; set; }
          public virtual ICollection&lt;ItemVersion&gt; Versions { get; set; }
          public virtual ICollection&lt;ItemTag&gt; Tags { get; set; }     
      }
  </code></pre>
  
  <p>The problem comes when it encounters the ItemTags collection, here is an ItemTag:</p>
  
  <pre><code>public class ItemTag
      {
          public Int32 ItemId { get; set; }
  
          public string Tag { get; set; }
  
          public Item Item { get; set; }
      }
  </code></pre>
  
  <p>Which you can see is not convention based and I have a configuration class for it as follows:</p>
  
  <pre><code>public class ItemTagConfiguration : EntityTypeConfiguration&lt;ItemTag&gt;
      {
          public ItemTagConfiguration()
          {
              HasKey(x =&gt; new {x.ItemId, x.Tag});
  
              HasRequired(x =&gt; x.Item)
                  .WithMany(y =&gt; y.Tags)
                  .HasForeignKey(x =&gt; x.ItemId);
  
          }
      }
  </code></pre>
  
  <p>Does anyone know of a way that I can use these <code>EntityTypeConfiguration</code> files with an ODataBuilder or web API?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>If found <a href="http://vfpefprovider.codeplex.com/discussions/444082">this page</a> which seems to indicate it might be possible with EF 6 which I am using.  What I want to do is this</p>
  
  <pre><code>ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();
  modelBuilder.EntitySet&lt;Dbf&gt;("Dbfs");
  //            modelBuilder.Configurations.Add(new DbfMap());  &lt;---- NO GOOD - Needs Class from DBContext we only have a model builder :(
  Microsoft.Data.Edm.IEdmModel model = modelBuilder.GetEdmModel();
  config.Routes.MapODataRoute("ODataRoute", "odata", model);
  </code></pre>
  
  <p>but the builder does not have a Configurations property.</p>