title: How do I map an OData query against a DTO to an EF entity?
body: <p>I have an ODataController in an Asp.Net Web Api application that allows OData queries. I'm only allowing reads, not updates. Instead of exposing the data model directly, I've created a set of DTOs. The property names on the DTOs do not necessarily match the properties on the EF model. This causes a problem when I try to use the OData query against the EF model. I've looked at other posts on StackOverflow around this subject but none of them seemed to resolve this issue.</p>
  
  <p>Here is what I have right now:</p>
  
  <pre><code>public IQueryable&lt;Customer&gt; GetCustomer(ODataQueryOptions&lt;Customer&gt; query)
  {
          ODataModelBuilder builder = new ODataConventionModelBuilder();
          builder.EntitySet&lt;Customer&gt;("Customers");
          builder.EntitySet&lt;RECORD&gt;("Records");
          builder.Namespace = "MyDataService.Models";
  
          var opts = new ODataQueryOptions&lt;RECORD&gt;(new ODataQueryContext(builder.GetEdmModel(), typeof(RECORD)), this.ActionContext.Request);
          var records = (IQueryable&lt;RECORD&gt;)opts.ApplyTo(db.RECORDS);
          return ConvertToCustomerList(records);
  }
  </code></pre>
  
  <p>This works until I reference specific fields in a select or filter. As soon as I reference a field in my OData query I get an ODataException like - <code>Could not find a property named 'LastName' on type 'MyDataService.Models.RECORD</code>. This is because the EF properties have a different naming convention. In this case it should be using "LAST_NAME".</p>
  
  <p>It seems like I need to parse the query and then replace the field references with the correct names. I found the ODataUriParser which seems like it could help with this but it's not as clean as I was hoping. </p>
  
  <p>Can anyone provide me some pointers in resolving this issue? Is there a better approach?</p>