Using Database First Approach in MVC5 (Visual Studio 2013 RC) Part 1

Rama Sagar
Posted by in ASP.NET MVC category on for Beginner level | Points: 250 | Views : 9563 red flag

Database First Approach is an alternative to the Code First and Model First approaches to the Entity Data Model which creates model codes (classes,properties, DbContext etc) from the database in the project and that classes behaves as the link between database and controller.


This article will help us to learn Database First Approach in ASP.NET MVC Application which connects with a database that exists already.Here Entity Framework 6 and scaffolding Technique is used for CRUD Operations.This gives a quick understanding for beginners.

Lets start first by creating our Database object model.Create a database and add the following table and a few records:

  • Step 1 Open Visual Studio 2013 RC and navigate to server explorer as shown below

                             Right Click on DataConnections-> AddConnection 


  • Step 2  In the next Window enter the server name and database name as shown in following image and Test connection.


  • Step 3 We can see that a new data connection is created in Server Explorer. Now right-click on connection and click on New Query


  • Step 4 Now lets Create Tables and insert some data using query as shown below

       ID int primary key identity (1,1),
       Name varchar(50),
       Marks int,
       Test int
CREATE TABLE Student_Report
       Report_ID int    primary key   Identity (1,1),
       Student_ID int foreign key references Students (ID),
       Name  varchar(50),
       Total  int,

CREATE TABLE Student_Details
       Details_ID int primary key identity (1,1),     
       Student_ID int foreign key references Students (ID),
       Class varchar(20),
	   Roll_No int,
	   Attendance int

Insert into Students (Name, Marks, Test)
values ('Ritwik', 463, 1),
('Anjali', 311, 1),
('Sanjay', 344, 1),
('Swathi', 375, 1),
('Babish', 356, 1),
('Praveen', 321, 1)

Insert into Student_Report (Student_ID, Name,Total)
Values (1,'Ritwik',964 ),
(2,'Anjali', 722),

Insert into Student_Details (Student_ID, Class, Roll_No, Attendance)
Values (1, 'Seventh', 18,98),
(2, 'Seventh', 19,75),
(3, 'Seventh', 20,85),
(4, 'Seventh', 21,65),
(5, 'Seventh', 22,75),
(6, 'Seventh', 23,50)
  • Step 5 Now lets check the table data
        Right click on Table--> Show Table Data



So far in this article we have learned how to create a database and work with the existing database in Visual Studio 2013 RC. we have now created all the tables and entered data into database.

In the next part we will create a ASP.NET MVC application which interacts with the database. 

   For Next part DB First Approach Part 2: Click Here



Page copy protected against web site content infringement by Copyscape

About the Author

Rama Sagar
Full Name: RamaSagar Pulidindi
Member Level: Silver
Member Status: Member,MVP
Member Since: 12/30/2012 1:51:40 AM
Country: India
A Software Profesional working in Microsoft .NET technologies since year 2008, and I work for Dake ACE. I am passionate about .NET technology and love to contribute to the .NET community at Dot Net Funda

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)