We are currently investigating the use of OData query syntax in our Web APIs. We are not looking to implement a full OData implementation - merely leverage the query syntax.
It is generally considered good application architecture to separate your application into several layers. In modern web applications these layers would include a data layer and UI/Transport layer which may model the information stored in your database differently when sending it to your customers.
eg: Your may have a database (Entity Framework) 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 expose this data to your customers in a different wire format:
public class EmployeeDto
{
public string Name {get; set;}
public string SecurityClearence {get; set;}
}
Using ASP.NET Web API and (presumably??) the Microsoft ASP.NET Web API OData libraries how would we achieve a scenario whereby our customers would write a query against the DTO format eg:
?$filter=(SecurityClearence eq 'TopSecret')
... and we would then translate that against 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 have thought of several ways to achieve this manually but I'm keen to know how other people would solve this because I feel my implementation so far is quite crude and unlikely to hold up to scrutiny.
Are there features of the Web API OData libraries (and related EDM libraries) that would achieve some or all of this for me?