CRUD Operations in Database-First Approach With ASP.NET MVC Framework Part-1

Here, we will learn about using DB First approach in ASP.NET MVC with entity framework. In DB first approach, Database is created first and from the database, POCO classes are generated automatically by Entity framework.

Firstly we will create the database in SQL Server.

Create the database

database-first-approach-with-asp-net-mvc-framework-1

Enter the database name

database-first-approach-with-asp-net-mvc-framework-2

Create the table.

database-first-approach-with-asp-net-mvc-framework-3

Enter the table fields and make Id column as Identity

database-first-approach-with-asp-net-mvc-framework-4

Enter the table name

database-first-approach-with-asp-net-mvc-framework-5

Open Visual Studio and create a new project.

Enter the project name and select ASP.NET Web Application

Choose MVC as a framework

Now we have to Install the Entity Framework for performing database related operations. So open the Package manager console.

database-first-approach-with-asp-net-mvc-framework-9

Write the command in the console

Install-Package EntityFramework

Add the ADO.NET Entity Data Model into the Models folder.

database-first-approach-with-asp-net-mvc-framework-11

Choose Data from Left Menu and choose ADO.NET Entity Data Model and give it a name.

Choose EF Designer From Database and Click next.

Select the Server and authentication types and database

Test the connection as it properly has done or not.

database-first-approach-with-asp-net-mvc-framework-15

Enter the Model name if you have to change.

database-first-approach-with-asp-net-mvc-framework-16

Choose the object you want to include in EDMX file.

database-first-approach-with-asp-net-mvc-framework-17

You will see the .edmx file

database-first-approach-with-asp-net-mvc-framework-18

Now your connection will be registered with your web application and you can see the connection string in Web.Config file present at the root folder.

database-first-approach-with-asp-net-mvc-framework-24

You will see that the Model is generated in the Models folder.

database-first-approach-with-asp-net-mvc-framework-19

Further, we will continue in Part-2

4 Comments

  1. Freebies

    Good post but I was wanting to know if you could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit more. Thanks!

    0
    0
    Reply
    1. Sure, I’ll, can you write what you expecting more on this subject?

      0
      0
      Reply
  2. Hairstyles Look

    I do not even know how I ended up here, but I thought this post was good. I do not know who you are but certainly you’re going to a famous blogger if you are not already 😉 Cheers!

    0
    0
    Reply
    1. Thanks for the feedback!

      0
      0
      Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories