Search code examples
asp.net-mvcasp.net-mvc-2

Where to write Database and Business logic in MVC?


As I am learning and working on Asp.Net MVC application, I want to know that what is the better place to write Business Logic and Data Access logic in MVC.

Where should I write DataAccess and Business Logic among three layers (Model, View and Controller) ??

Could anybody please tell me the correct way to write the code for this.

Scenario: I want to retrieve all the employees where employee name like 'Mi%' ( I have SQL procedure to execute and retrieve the data.)

PS: Want to know that where I should create instance of Business Logic class and where I should create instance of Data Access layers class?

Thanks in advance.


Solution

  • Business logic should be in the Model.

    Data Access can either be its own later your Controllers call, or automated in an ORM that your Controller will call through repositories.

    A walk-through covering this can be found in Nerd Dinner, look for the free download section.