This project is read-only.

Web API, OData and layered architecture

Topics: ASP.NET Web API
Jan 10, 2013 at 10:27 PM

Our application architecture contains the following layers:

  • Presentation Layer
  • Service Layer
  • Business Layer
  • Data Layer

The Service layer uses WebAPI to expose RESTful services.  When retrieving data we would like to standardize on some syntax for paging.  OData seems like a great place to start.  The service layer utilizes the business layer to retrieve data.  The business layer, in turn utilizes the data layer which is built on the Entity Framework.  The data layer passes a list of entity objects back to the business layer.  The business layer then converts the list of entity objects to a list of DTOs for public consumption.  

Adding OData to our service appears to manipulate the IQueryable set of DTOs with one major performance issue.  The OData operations are performed on the list of DTOs.  If we pass in something like the following:


The data layer retrieves all 100,000 codes, passes them to the business layer which in turn converts them to a list of DTOs.  OData then applies the "paging".  It works, but it's slow.

It would be nice if there was a way to pass the ODataQueryOptions down to the data layer so the database would filter the list.  Is this something in the works?  I believe our system design implements many of Microsoft's best practices for system architecture.  This must be an issue for other developers out there?

I have installed Web API OData 0.3.0-rc.


Jan 10, 2013 at 11:35 PM

We provide support for parsing the OData query, converting it to a LINQ expression and applying it to an IQueryable. If your business layer does not expose access to your data as an IQueryable, then you need to provide a separate mapping from the parsed OData query to whatever query mechanism your business layer exposes. You can get access to the parsed abstract syntax tree for the query from the ODataQueryOptions so that you can perform this mapping.