Introduction
Entity Framework is a gateway between your application and your
database. A simple reason why Entity Framework stands out is that it
automatically generates object classes that map with your database
tables. In ASP.NET MVC5 platform entity framework also has the ability
to generate complex types of object mapping classes that correspond with
your database store procedures using entity framework database first
approach.
Today, I shall be demonstrating Entity Framework database-first approach with ASP.NET MVC5 platform.

Prerequisites
Following are some prerequisites before you proceed any further in this tutorial.
- Knowledge of ASP.NET MVC5.
- Knowledge of HTML.
- Knowledge of JavaScript.
- Knowledge of Bootstrap.
- Knowledge of Jquery.
- Knowledge of C# Programming.
The example code is
being developed in Microsoft Visual Studio 2017 Professional. I have taken the data sample from AdventureWorks for SQL server 2014
Let's begin now.
Step 1
Create a new MVC web project and name it "MVCDatabaseFirst".
Step 2
Although you can create your entity framework model inside any hierarchy of the project, I prefer the "Models" folder, to keep code cleaner. So, right-click on your "Models" folder and then click "Add->New Item".

Step 3
Then, choose "ADO.NET Entity Data Model", name it "DataAcessModel" and click "Add".

Step 4
Now, from "Entity Data Model Wizard" choose "EF Designer from database", since I am creating Entity Framework database-first approach model. Then, click "Next".

Step 5
On the "Choose Your Data Connection" window, click "New Connection" button.

Step 6
In "Connection Properties"
window, provide your SQL Server connection configuration. Then, click
"OK". Your database connection string will be stored
in the "Web.config" file.

Step 7
Now, on "Choose Your Data Connection" window, click "Yes, include sensitive data in the connection string." option and click "Next" as shown below.

Step 8
Now, on "Choose Your Database Objects and Settings"
window, choose your target database objects. In my case, I have selected only the store procedures. Click "Finish".

Step 9







Prakash BesraPosted Jul 28, 2020, 11:47 AM
Thank you Asma, I went through whole articles(this and https://www.asmak9.com/2016/03/aspnet-mvc5-integrating-existing.html). It really helped me understand how database first approach works with login and claim based identity. Further, I have some queries, In the second article(database approach-login), since cookies are used for login/claims persistence, Is it problematic if the data stored is high as browsers normally can store around 4KB cookies? Regarding claims, Let's say I have permission e.g In Book view, user can read and borrow but Librarian can add, edit books. Can these types of permission(for user and librarian) be used in claim?Will it be a good design principle? Any help would be appreciated.
Prakash BesraPosted Jul 27, 2020, 5:31 AM
How will you implement User Login and User Roles in this project?
Amit MohantyPosted Jul 25, 2019, 11:23 PM
Nice article