0% found this document useful (0 votes)
8 views3 pages

DB First Code Step by Step by - Tejas Koshti

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

DB First Code Step by Step by - Tejas Koshti

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

DB First Code Step by Step By - Tejas Koshti

__________________________________________________________________________

1.Add Extension:

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

2.Make DB
1. Dept (Parent)
​ 2. Employee (Child)
__________________________________________________________________________

3. NugGet Console

Put This In Console :


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

Note : Yash1 is DataBase Name Eg: ActsJan25


__________________________________________________________________________

4. Update: Program.cs

public static void Main(string[] args)


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

options.UseSqlServer(builder.Configuration.GetConnectionString("Yash1Conte
xt")));
__________________________________________________________________________

5. Update: JSON File

{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"ConnectionStrings": {
"ActsJan25Context": "Data Source=(localdb)\\MsSqlLocalDb;Initial
Catalog=ActsJan25;Integrated Security=true;MultipleActiveResultSets=true"
},
"AllowedHosts": "*"
}

__________________________________________________________________________

6. Now Make Controllers For All Class

Eg 1. Dept (Parent)
​ 2. Employee (Child)

__________________________________________________________________________

😀
7. After All Successful Code
​ Run The and Enjoy :

__________________________________________________________________________
__________________________________________________________________________

You might also like