Click here to Skip to main content
15,888,286 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C#
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.
Posted
Updated 25-Jul-16 4:11am
v2
Comments
johannesnestler 26-Jul-16 9:54am    
examples are for simplicity - I use EntityFramework and OData with a separate DAL - I hope you don't expect Enterprise-Level code in examples and tutorials...
So if you application is "big enough" go for your usual layering I'd say!
sunset747 27-Jul-16 10:09am    
Can you specify "I use EntityFramework and OData with a separate DAL". I really need three layers and I also want to use oData. But in all the examples with three layers + oData filtering is done on the web server, not in the database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900