Today, I am going to explain a very interesting topic; “How to use Code First Approach in ASP.NET MVC with Generic Repository Pattern”. So, first I will explain what Code First approach is and why we use it and later I will explain you about Repository Pattern. 


 




test



MVC or Model View Controller is a software design pattern to develop web application.  MVC is not a new concept created by Microsoft to develop Web application in Asp.Net MVC. Even MVC is also used to develop iOS framework. So, we can say it is a general concept of Software Development. MVC is stand for Model View Controller. In short. Model is Data objects like Business logic, validation and DB access.View is User Interface (UI) and Controller handles the user request and work with View and Model.



Asp.Net MVC is nothing but a framework introduce by Microsoft. It is lightweight and open source. It is used to building highly testable, scalable and well designed clean application. Microsoft introduce first MVC version MVC 1.0 in 2009. Here I am explaining all the versions and its feature.



Repository Pattern is used to create an abstraction layer between data access layer and business logic layer of an application. Repository directly communicates with data access layer [DAL] and gets the data and provides it to business logic layer [BAL]. The main advantage to use repository pattern to isolate the data access logic and business logic, so that if you make changes in any of this logic that cannot effect directly on other logic.



If we use same name controller in Area and Root in Asp.Net MVC application than we will conflict and throw an error like below.

~/Controllers/HomeController.cs

~/Areas/Blog/Controllers/HomeController.cs

Multiple types were found that match the controller named 'Home'. This can happen if the route that services this request ('{controller}/{action}/{id}') does not specify namespaces to search for a controller that matches the request

.To resolve it we have to provide the proper namespace when creating route for both.



In this articles, I will try to explain the structure of Asp.Net MVC project. When we create a new project than there are lots of folders and files are available. So, what is the purpose of these folders and files. Why we use Model, Controller, View, Areas, App_Data etc folder. What type of files manage inside it..



Today, I am going to demonstrate what is routing in Asp.Net MVC and how do we use it in our Asp.Net MVC application. Routing is used to map the incoming request to particular MVC controller action. So, Routing is a pattern matching system that map incoming request with specific action. Route table is used to decide at run time to match the incoming request by Route Engine.



Database First is nothing but only a approach to create web application where database is available first and can interact with database. In this database, database is created first and after that we manage the code. The Entity Framework is able to generate a business model based on the tables and columns in a relational database.

Basically, there is some scenario where we need to create database first like all table, primary key and foreign key relationship and then on the basis of database we generate our code.




Pages : 1 2

Search
Latest eBook Download
Categories
Category Loading....
Recent Articles
Recent Articles Loading....
Popular Articles
Popular Articles Loading....
Find Me


SIGN UP TO OUR NEWSLETTER