Referring
this question:
I want to start to write my Web API Services with ODataControllers in the future, but I am still facing a question I could not answer with Google:
All the oData Examples I found on the internet (for instance
ODataSamples) are accessing the DBContext object
directly in the Controller:
public class MoviesController : ODataController
{
private MoviesContext _db = new MoviesContext();
public IHttpActionResult Get()
{
return Ok(_db.Movies);
}
}
So the presentation layer is publishing database entities directly, what obviously hurts the three tier architecture of a well structured software.
Usually I have three model types: View models in the PL, business models in the BL and entity models in the DAL.
But with oData + Entity Framework all examples do not follow this consensus anymore. Is this only for simplicity or is it even okay to code that way?
Any suggestions?
What I have tried:
I could forward my ODataQueryOptions from the Controller to my DAL and apply it to the EDM there. The result bubbles back to my PL in the appropriate classes.
Another idea is to use expression trees in the BL, but I did not find out how to do this. It was only an idea.