What are the main approaches to using Entity Framework Core?

Beginner

Answer

EF Core supports three main approaches:

  1. Code First: Define entity classes first, then generate database schema
    • Start with C# classes (entities)
    • Use migrations to create and update database
    • Good for new projects with full control over data model
  2. Database First: Start with existing database, generate entity classes
    • Use Scaffold-DbContext command
    • Generates DbContext and entity classes from existing database
    • Good for existing databases or database-driven development
  3. Model First: Design model using visual designer (less common in EF Core)
    • Primarily supported through external tools
    • Not as prominent as in EF6