CRUD operation with Entity Framework 6 Database First Approach using MVC 5

CRUD  with Entity Framework 6 Database First Approach using MVC 5


Create a database

Create Database BlogPost
Go
 Use BlogPost
GO  
Create Table Class
(ID int identity(1,1) Primary key
,Name nvarchar(200)
,Abbreviation nvarchar(10)
,IsEabled bit default (1)
,Create_Date datetime default getdate() ,Modify_Date datetime default getdate()
)
GO
Insert into Class(Name,Abbreviation)
                        values('B.A','BA'),
                                    ('B.TECH','BTech'),
                                    ('M.C.A','MCA'),
                                    ('M.TECH','MTech')                         
GO
Create Table Student(
ID int identity(1,1) Primary key
,Name nvarchar(200)
,ClassID int
)
GO
ALTER TABLE Student  ADD  CONSTRAINT [Student_Class] FOREIGN KEY(ClassID)
REFERENCES Class (ID)

 the database BlogPost created and two table also


Open Visual studio and create new mvc web application. Add model by right clicking on Model folder. 

Choose new item and filter for data templates

Select top 1 and Click add



Create a new connection to provide the sql server database connection to entity


save connection string to web.config and proceed to next screen

choose the 6.x

Choose the database, you wants to work with.

 Add new controller and view to presentation information and perform crud.



 Choose the model class and data context and add.
 we will get the error on adding the controller. Build project first and add controllers.
 the above images shows the controller and view added.

hit f5 and see output in browser.



 ~
Sunit
technocrats@sunitkanyan.in

CRUD  with Entity Framework 6 Database First using MVC 5