Thursday, August 10, 2023

How to generate class from Db or create db from class

 After install Microsoft.EntityFrameworkCore, Microsoft.EntityFramwworkCore.Sqlserver, Microsoft.EntityFrameworkCore.Tools

From PM console command line
Code First
1) Add-Migration InitialCreate  (it will create a migration fold with code)
2) Update-database ( it will create a DB with data table defined)

From PM console command line drop down list, set Default Project which will  accommodate class
DB first:
scaffold-dbcontext  "Server=sqldev;Database=Timesheet;Trusted_Connection=True;TrustServerCertificate=true;MultipleActiveResultSets=true;"  Microsoft.EntityFrameworkCore.Sqlserver -outputdir Models -force

Blog Archive