Friday 12 June 2015

CRUD Operation in Asp.Net MVC using Entity Framework

Here we will learn CURD Operation in MVC Using Entity Framework.
For More Detail About Entity Framework Go to EntityFramework Tutorials.
1.   First Go to Sql Server and Execute following query for Student Department and Student Information.
Create table stdDepartment
 Id int primary key identity,
 Name nvarchar(50)

Insert into stdDepartment values('Teacher')
Insert into stdDepartment values('HOD')
Insert into stdDepartment values('Professor')

Create Table Student
     StudentID int identity primary key,
     StudentName nvarchar(50),
     Gender nvarchar(50),
     SchoolName nvarchar(50)

Alter table Student add DepartmentId int

Alter table Student
add foreign key (DepartmentId)
references stdDepartment(Id)

Insert into Student values ('Munesh','Male','VIT',1)
Insert into Student values ('Rahul','Male','ABC',2)
Insert into Student values ('Reet','Female','XYZ',2)
Insert into Student values ('Anshuman','Male','PQR',3)
Insert into Student values ('Simi','Female','NIT',3)
Insert into Student values ('Nency','Female','MIT',2)
Insert into Student values ('XYZ','Male','PQR',1)

Go to Visual stdio -> NewProjct -> Select MVC4 Web Application (give application name) -> select Empty website with Rezor.

2.   Now Install Entity Framework to your application For this Go here.
3.   After Installing Entity Framework Add “Ado.Net Entity DataModal” by right click on “Modals”, And Give the name for this as “StudentDataModal”.

4.   When You will click Add button here you will see another window for  “EntityData modal Wizard” from there you select “Generate From DataBase”, And Click Next
5.   In This window you give you database connection and select your database ,

After click, on Continue Button Below screen will show there you will database connection and Test your connection and click OK

Then Click Next
6.   In this screen select your Database Tables and give Modal Name then click FINISH Button

7.   When you will click on finish button it will create StudentDepartment and Student Entity, change their  name also

8.   Right Click on Controller and add a controller and give details in controller like below

After that click on Add
9.   When you will click on add it will create View automatically , You can see in View folder

10.                At this time if we run our application it will error that “Resource cannot found” this is because in RouteConfig file the default controller name is “Home “ controller , so change this controller name as “Student” controller and run application.

Delete the following Script from “Create.csHtml and “Detail.csHtml” View

@section Scripts {

Now run your application and see the output and perform all the operations.


  1. This article is very useful for those who are preparing for an interview in IT company. Whether you are experienced or fresher, this article will cover all SQL query questions from basic to advanced level.

  2. Sir, here is great example of CRUD Operations In JTable Using MVC

  3. Thank you because you have been willing to share information with us. we will always appreciate all you have done here because I know you are very concerned with our.


C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...