0% found this document useful (0 votes)
13 views

Db First

Uploaded by

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

Db First

Uploaded by

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

Db first approach

1. Add Nuget Packages


Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools

2. Package Manager Console


Scaffold-DbContext "Data Source=(localdb)\MsSqlLocalDb;Initial
Catalog=YcpDes24;Integrated Security=true" Microsoft.EntityFrameworkCore.SqlServer
-OutputDir Models

Note : read more at


https://docs.microsoft.com/en-us/ef/core/managing-schemas/scaffolding?tabs=vs

3. Add EF service in Program.cs

public static void Main(string[] args)


{
builder.Services.AddControllersWithViews();
builder.Services.AddDbContext<Yash1Context>(options =>

options.UseSqlServer(builder.Configuration.GetConnectionString("Yash1Context")));

4. Specify connection string in appsettings.json


"ConnectionStrings": {
"Yash1Context": "Data Source=(localdb)\\MsSqlLocalDb;Initial
Catalog=Yash1;Integrated Security=true;MultipleActiveResultSets=true"
}

You might also like