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

Rama Sagar
Posted by in ASP.NET MVC category on for Beginner level | Points: 250 | Views : 11590 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.

Introduction


This article shows the walk through of an ASP.NET Web application in a MVC 5 project template which connects with an existing database. we have a database with which we can create a model that supports interaction with the application and the performance of (CRUD) operations.

Here we can see the database connectivity with the Entity Framework Database First Approach. Using Scaffolding,we can generate code for(CRUD) Operations automatically. In this part we will know the Database composition with the web application. 

As this is the Continuation of previous Article Please Click Here

Lets start with Creating a ASP.NET Web Application using MVC 5

  • Step 1  Open Visual Studio 2013 RC  -> click on File -> New Project -> Create new ASP.NET WebApplication -> Name it as StudentApplication
     


  • Step 2  Select MVC Project Template 
         

   
  
  • Step 3 Now lets use Entity Model as shown
         Right Click on Model Folder-->Add--> New Item 




  • Step 4 Select ADO.NET Entity Model
   


  • Step 5  In the next wizard, select Generate from database

     

  •   Step 7   In the next wizard, select the data connection that was created earlier. and Provide the Connection String name.
 

  •   Step 8  Select the tables which we have created 



  •  Step 9 Now we can see automatically created Model and a generated view for the model as shown below.

  


  • Step 10  Now lets start creating a controller and view
 MVC 5 can create a Controller with the corresponding views using Entity Framework 6. We need to just use Scaffolding for Crud Operations. So let's start with the following procedure.

 Right click on Controllers folder-->Add-->Scaffold

    

  •   Step 10 Select MVC 5 Controller with Views using Entity Framework
  


  •  Step 11  Enter the controller name and choose the corresponding model and the DbContext class as shown below:

  


  • Step 12  In the same way create controllers and views for all the tables

    
  • Step 12  Now run the application and we will see the following output where we can perform the CRUD operations
    

Conclusion


So far in this article we have learned how to create a new ASP.NET Web Application using MVC Template and add the database model with the application and perform the CRUD operations in the Database First Approach in MVC 5.


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
ramasagar
http://www.ramasagar.com
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)