Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am new to entity framework .i have used normal mic razor view for all operation using controller..in entity framework do i need to write the code in model class to connect with database and then what about controller
Posted

1 solution

I seriously suggest picking up a book on MVC4 or above and EntityFramework Code First and working through them. You're not going to learn this stuff by constantly asking questions in forums.

No, you don't normally put the database access code in the class objects. You normally put that code in separate classes.

In a simplified layout, when I do MVC and EF stuff, I put all of the database code in classes that I call "ModelServices". These classes do all the database work and return the model objects back to whatever code that calls them, be they Controllers or Business classes.

My Controller classes handle enforcing business rules form the perspective of the view, managing data available to manipulate other data, translating between database classes and view model classes, handle validation and exposing and managing an external API.
 
Share this answer
 

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