0% found this document useful (0 votes)
291 views5 pages

Entity Framework Core - Database First Steps

This document provides steps for using Entity Framework Core with an existing database (database first approach) in an ASP.NET Core application. It outlines adding required packages, using Scaffold-DbContext to generate entity models from the database, and how to update the models and database if changes are made.

Uploaded by

Javed Iqbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
291 views5 pages

Entity Framework Core - Database First Steps

This document provides steps for using Entity Framework Core with an existing database (database first approach) in an ASP.NET Core application. It outlines adding required packages, using Scaffold-DbContext to generate entity models from the database, and how to update the models and database if changes are made.

Uploaded by

Javed Iqbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ENTITY FRAMEWORK CORE

(DATABASE FIRST)
ASP.NET Core 7.0 or later

25 JULY 2023
Entity Framework Core Tutorial 25 July 2023

Entity Framework Core – Database First

Step #1: Create a New ASP.NET Core Web Application in Visual Studio 2019.

Page | 1
Entity Framework Core Tutorial 25 July 2023

Step #2: Add the required Packages as shown below.

Step #3: In Project Manager Console and add the following command
PM> Scaffold-DbContext "Data Source=DESKTOP-6AVBNVP\SQLEXPRESS;Initial
Catalog=SCBuildersWebsiteDBV2;Integrated Security=True"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

This will all the Generate Models in Models folders as shown below.

Page | 2
Entity Framework Core Tutorial 25 July 2023

Page | 3
Entity Framework Core Tutorial 25 July 2023

Other Migrations

PM> Scaffold-DbContext "Data Source=DESKTOP-6AVBNVP\SQLEXPRESS;Initial


Catalog=SCBuildersWebsiteDBV2;Integrated Security=True"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

PM> Scaffold-DbContext "Data Source=DESKTOP-6AVBNVP\SQLEXPRESS;Initial


Catalog=SCBuildersWebsiteDBV2;Integrated Security=True"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models –Context TestContext

PM> Scaffold-DbContext "Data Source=DESKTOP-6AVBNVP\SQLEXPRESS;Initial


Catalog=SCBuildersWebsiteDBV2;Integrated Security=True"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -DataAnnotations

PM> Scaffold-DbContext "Data Source=DESKTOP-6AVBNVP\SQLEXPRESS;Initial


Catalog=TestDBEFCore2;Integrated Security=True"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models/EF -Context TestDbContext -
DataAnnotations (Models/EF – Will store in EF Folder Inside Models Folder)

To Update Database Changes

PM> Scaffold-DbContext "Data Source=DESKTOP-6AVBNVP\SQLEXPRESS;Initial


Catalog=SCBuildersWebsiteDBV2;Integrated Security=True"
Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -Force

Page | 4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy