TodoList web application is created using MVC - 4 architecture, code-first Entity Framework (ORM) and Jqgrid for displaying the data.
Source Code
You can download the source code from
https://dotnetsourcedileep.codeplex.com/I am dividing this topic in to 2 sections.
Section 1: contains basic theoretical details of the technologies that we are used and the advantages of using ASP.net MVC-4, Code first Entity Framework and JQgrid technologies.
Section 2: contains the practical implementation of step by step creating a simple TodoList application using ASP.net MVC-4, Code first Entity Framework and JQgrid.
Section 1:
MVC
- MVC is a pattern for developing applications that are well architected and easy to maintain. So using MVC we can develop testable, flexible, scalable, extensible standard based applications.
- MVC is not a replacement of Asp.net web forms based development. This sits on top of Asp. net development. MVC framework is defined in "System.Web.MVC.Assembly".
- MVC works on Conventions over configurations.
Model
- Model represents the application data domain. It can contain a logic related to data domain.In short the application business logic is contained with in the model.
- Model contains a pieces of C# classes with set of properties and validations defined on top of it using data annotations. It can also contain data access, data aggregation logic etc.
- Model can be entities or business logic.
View
- View represents the presentation layer of the web applications.
- View manages the display of information based on the data of the model i.e. requested by the controller.
- View Represents the User interface, with which the end user interacts. In short all the UI related logic is contain the View.
Controller
- Controller handles the user interaction with the web application.
- User requests comes through the controller to model and manipulates the records from it and render the data using view to UI.
- Controller contains the control flow logic.
- Controller contains the set of action methods.
Why MVC or Advantages of Using MVC
There are many advantages of using MVC as follows: -
- MVC helps us to develop loosely coupled architecture.
- Complex applications can be easily managed.
- Separations of concerns is possible by dividing the application in to Model,View and Controller.
- Extensive support for Test Driven Development(TDD). Unit testing will be easy, an additional layer of testing will provide yet another layer of defense against unexpected behavior.
- Asp. net MVC is light weight as they do not use view state.
- SEO(Search Engine Optimization) Clean Url's and no extension methods are used for locating the physical files.
- Rich javascript support with UnObstrusive javascript, Jquery Validation with Json binding.
- No Post back events.
- Expressive views including the new Razor view engine and HTML - 5 enabled.
Entity Framework
The Microsoft ADO.Net Entity Framework is an Object Relational Mapping (ORM) framework that enables developers to work with relational data as a domain specific object, eliminating the use of most of the data access plumbing code that developers usually need to write.
Code First Approach
Code First is mainly used in Domain Driven Design(DDD) approach. We can focus on the domain design and start writing the classes as per the domain requirement rather than design the database first and then you create the classes that matches your database design. Code first API's will create the database on the fly based on your entity classes and configuration.
Why Entity Framework?
Basically in the real world scenarios there are 2 types of groups or models will be present like Logical Data Model and Object Oriented Domain Model
Logical Data Model
Almost any business application today as to speak to a relational database. These relational database can also say it has a Backend SQLSERVER contains all the Stored Procedures, tables with foreign key, view etc. Which will be handled by 1 group of people called as database centric.
Object Oriented Domain Model
Applications are developed completely different from the logical data model. These Object Oriented Domain Model deals with objects, behaviors, properties, inheritance, polymorphic etc. Which will be handled by 1 group of people called as application centric.
Impedence Mismatch
As a result of above 2 models impedance mismatch occurs, as the developers devote a lot of time and energy writing code to translate between how the database likes to see the data and how the application likes to see the data.
So Ado .net Entity Framework seeks to remedy to problem by providing the layer of abstraction between the logical data model and the application domain model.
Advantages of using Entity Framework
- Entity framework enables developers to create data access application by programming against conceptual application model instead of programming against relational storage schema.
- Application can work in terms of more application centric conceptual model including types with inheritance, complex members and relationships.
- Entity framework is an ORM tool that provide simple API to perform CRUD operations. IT helps us to automatically work on DML and DDL operations from the front end, instead of going and doing it manually from the back end.
- Entity framework provides strongly typed classes, giving intellisense support, compile time and debugger options.
- Plumbing and mapping is done for you. So developers need not to write most of the data access plumbing code that normally required(e.g.ADO.net)
- Lot of time will be saved and it helps us to quickly develops the application and concentrate more on business centric details.
JQGRID
Jqgrid is an ajax enabled javascript control that provides solution for representing and manipulation tabular data on the grid. Since grid is a client side solution loading data dynamically through ajax call backs, it can be integrated with any server side technology, including php, ASP java servelets, JSP and perl.
JQGrid uses Jquery javascript library.