Mid EF Core

How do you reverse engineer a database in EF Core (DB First) into entity classes & DbContext?

Use the CLI or Package Manager Console:

dotnet ef dbcontext scaffold "YourConnectionString"

Microsoft.EntityFrameworkCore.SqlServer -o Models

Scaffold-DbContext "YourConnectionString"

Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

✅ It generates:

  • Entity classes
  • DbContext class
  • Mappings based on database schema

More from Entity Framework Core Tutorial

All questions for this course