We are currently exploring the use of OData query syntax in our web APIs. We are not aiming to implement a full OData implementation - we just use the query syntax.
It is generally considered a good application architecture for dividing your application into several levels. In modern web applications, these layers will include a data layer and a user interface / transport layer, which can model the information stored in your database in different ways when sent to your customers.
for example: you may have an Entity Framework database model that looks like this:
public class Employee { public Guid Id {get; set;} public string Name {get; set;} public int AccessLevel {get; set;} }
but your web APIs may provide this data to your clients in a different format:
public class EmployeeDto { public string Name {get; set;} public string SecurityClearence {get; set;} }
Using the ASP.NET Web API and (presumably?) The Microsoft ASP.NET OData Web API libraries, how could we reach a scenario where our clients would write a query regarding the DTO format, for example:
?$filter=(SecurityClearence eq 'TopSecret')
... and then we will translate this into our data format. eg:
?filter=(AccessLevel eq 007)
or some other format that will allow me to dynamically query my database, such as an expression. eg:
db.Employees.Where(translatedExpression);
I thought of several ways to accomplish this manually, but I am interested in understanding how other people will solve this because I feel that my implementation is still pretty crude and is unlikely to lend itself to verification.
Are there any OData Web API library features (and related EDM libraries) that some or all of this could get for me?
c # expression asp.net-web-api asp.net-web-api-odata ado.net-entity-data-model
Gavin osborn
source share