title: support of @odata.bind in asp.net web api (link to existing entity during post)
body: <p>I'm having a really hard time migrating from WCF data service to web api odata v4. I'm stuck on the following issue:</p>
  
  <p><strong>odata web api doesn't seem to support @odata.bind.</strong> </p>
  
  <p>I've found the following link: 
  <a href="https://github.com/OData/WebApi/issues/158" rel="noreferrer">https://github.com/OData/WebApi/issues/158</a>
   There someone suggested to implement an own <code>ODataEntityDeserializer</code> derived class like so:</p>
  
  <pre><code>public class ExtendedODataEntityDeserializer : ODataEntityDeserializer
  {
      public ExtendedODataEntityDeserializer(ODataDeserializerProvider deserializerProvider) : base(deserializerProvider)
      {
      }
  
      public override void ApplyNavigationProperty(
          object entityResource, 
          ODataNavigationLinkWithItems navigationLinkWrapper, 
          IEdmEntityTypeReference entityType, 
          ODataDeserializerContext readContext)
      {
          base.ApplyNavigationProperty(entityResource, navigationLinkWrapper, entityType, readContext);
  
          foreach (var childItem in navigationLinkWrapper.NestedItems)
          {
              var entityReferenceLink = childItem as ODataEntityReferenceLinkBase;
  
              if (entityReferenceLink != null)
              {
                  var navigationPropertyName = navigationLinkWrapper.NavigationLink.Name;
                  Uri referencedEntityUrl = entityReferenceLink.EntityReferenceLink.Url;
  
                  if (!referencedEntityUrl.IsAbsoluteUri)
                  {
                      referencedEntityUrl = new Uri(readContext.Request.RequestUri, referencedEntityUrl);
                  }
  
                  var linkedEntities = (Model.LinkedEntityCollection)entityResource;
                  linkedEntities.Add(navigationPropertyName, referencedEntityUrl);
              }
          }
      }
  }
  </code></pre>
  
  <p>LinkedEntityCollection is a base class for my entity classes that serves as dictionary (<code>MyEntity : LinkedEntityCollection</code> implementation is trivial). </p>
  
  <pre><code>public class ExtendedODataDeserializerProvider : ODataDeserializerProvider
  {
      private static ExtendedODataDeserializerProvider _instance = null;
  
      private ExtendedODataDeserializerProvider()
      {
          _instance = this;
      }
  
      public static ExtendedODataDeserializerProvider Instance
      {
          get { return _instance ?? new ExtendedODataDeserializerProvider(); }
      }
  
      public override ODataEdmTypeDeserializer GetEdmTypeDeserializer(Microsoft.OData.Edm.IEdmTypeReference edmType)
      {
          return DefaultODataDeserializerProvider.Instance.GetEdmTypeDeserializer(edmType);
      }
  
      public override ODataDeserializer GetODataDeserializer(Microsoft.OData.Edm.IEdmModel model, Type type, System.Net.Http.HttpRequestMessage request)
      {
          return new ExtendedODataEntityDeserializer(DefaultODataDeserializerProvider.Instance);
      }
  }
  </code></pre>
  
  <p>Registering in the http configuration:</p>
  
  <pre><code>public static void Register(HttpConfiguration config)
  {
      ODataModelBuilder builder = new ODataConventionModelBuilder();
  
      // registering entities: builder.EntitySet&lt;T&gt;("EntityName") ...
  
      ODataBatchHandler batchHandler = new DefaultODataBatchHandler(new HttpServer(config));
      batchHandler.MessageQuotas.MaxOperationsPerChangeset = 10;
      batchHandler.MessageQuotas.MaxPartsPerBatch = 10;
  
      var odataFormatters = ODataMediaTypeFormatters.Create(DefaultODataSerializerProvider.Instance, ExtendedODataDeserializerProvider.Instance);
  
      config.Formatters.Clear();
      config.Formatters.AddRange(odataFormatters);
  
      config.MapODataServiceRoute(routeName: "Central", routePrefix: "Odata", model: builder.GetEdmModel(), batchHandler: batchHandler);
  }
  </code></pre>
  
  <p>However if you do use this hack you loose the capability of creating links between enities like described in this aritcle: <a href="http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/entity-relations-in-odata-v4" rel="noreferrer">http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/entity-relations-in-odata-v4</a></p>
  
  <p>The "@odata.id" doesn't get parsed, it is assumed that it's an entity in the function <code>ODataEntityDeserializer.Read</code>. Maybe I'm missing somthing fundamentally here, since I'm fairly new to web api (<code>config.Formatters.Clear()</code> seems a bit harsh). Or is there any other workaround to support @odata.bind?</p>
  
  <p>Is there any chance that this feature gets implemented in the near future?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I got my hack working. The Problem was that I should have derrived <code>ExtendedODataDeserializerProvider</code> from <code>DefaultODataDeserializerProvider</code> instead of <code>ODataDeserializerProvider</code> and return the deserializers accordingly:</p>
  
  <pre><code>public override ODataDeserializer GetODataDeserializer(
       Microsoft.OData.Edm.IEdmModel model, 
       Type type,     
       System.Net.Http.HttpRequestMessage request)
  {
      if (type == typeof(ODataActionParameters) || 
          type == typeof(ODataUntypedActionParameters) || 
          type == typeof(Uri))
      {
          return base.GetODataDeserializer(model, type, request);
      }
  
      return new ExtendedODataEntityDeserializer(DefaultODataDeserializerProvider.Instance);
   }
  </code></pre>
  
  <p>So the question that remains: when do we get @odata.bind support in asp.net webapi odata? </p>