title: Custom serializer not working in Web API 2 for oData 4 when the URL contains $select
body: <p>I implemented a custom serializer by inheriting ODataEntityTypeSerializer. The serializer sets the value of "MessageStateName" by getting the name of BayStateEnum from the value of "MessageState".
  It works well only except when the URL contains "$select". I debugged the code and found it was executed and entityInstanceContext.EntityInstance had the correct value, but entityInstanceContext.EdmModel, which was of type System.Web.OData.Query.Expressions.SelectExpandBinder.SelectSome, still had an empty "MessageStateName".</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class CustomEntitySerializer : ODataEntityTypeSerializer
  {
      public CustomEntitySerializer(ODataSerializerProvider serializerProvider)
          : base(serializerProvider)
      {
      }
      public override ODataEntry CreateEntry(SelectExpandNode selectExpandNode, EntityInstanceContext entityInstanceContext)
      {
          if (entityInstanceContext.EntityInstance is SmartLinkInfoModel)
          {
              var smartLinkInfo = entityInstanceContext.EntityInstance as SmartLinkInfoModel;
              if (smartLinkInfo.ModemIMEI != null)
              {
                  smartLinkInfo.ModemIMEIString = "0x" + string.Join(string.Empty, smartLinkInfo.ModemIMEI.Select(b =&gt; (b - 48).ToString()));
              }
              if (smartLinkInfo.SmartLinkHardwareId != null)
              {
                  smartLinkInfo.SmartLinkHardwareIdString = "0x" + string.Join(string.Empty, smartLinkInfo.SmartLinkHardwareId.Select(b =&gt; b.ToString()));
              }
              if (smartLinkInfo.XbeeSourceId != null)
              {
                  smartLinkInfo.XbeeSourceIdString = "0x" + string.Join(string.Empty, smartLinkInfo.XbeeSourceId.Select(b =&gt; b.ToString()));
              }
          }
          else if (entityInstanceContext.EntityInstance is BayMessageModel)
          {
              var bayMessage = entityInstanceContext.EntityInstance as BayMessageModel;
              bayMessage.MessageStateName = Enum.GetName(typeof(BayStateEnum), bayMessage.MessageState);
          }
          return base.CreateEntry(selectExpandNode, entityInstanceContext);
      }
  }
  </code></pre>