I am trying to understand how the database access model works in asp.net mvc, some examples has the work in the controller but other has examples in the model.
I want to know how to do it using ado.net, the best practices is use a class in the model layer and try my database access there?
all examples are with EF and LINQ, I want to know the best way to do it using ado.net.
the database access is in model or controller?
Here is an architectural design to consider:
Repository.
The website has references to the Models and DataAccess projects. The DataAccess project also has a reference to the Models project.
This way, the data access code is separate. It is easier to find and maintain. It could be used in another solution. You could even swap it out for a completely different data access layer — say, switching from Linq to SQL to Entity Framework or classic ADO.Net.
By keeping the Models in a separate project, they can be referenced by both the website and the data access layer. In addition, the Models project could be used in other solutions, just like the loosely-coupled data access layer.
Separating the layers this way makes it easier to add testing, too. That would be made easier if the data access layer/repository utilizes interfaces and dependency injection.