Port from EF6 to EF Core - the Hybrid Approach

Two common approaches are to generate your database from code and use migrations, or generate your entities from the database using reverse-engineering. In the hybrid approach, you don't generate anything. Instead, you let the database and codebase evolve and use model configuration to keep the two in sync. This page contains some tips for success using the hybrid approach:

  1. First, read the guides for code as source of truth and database as source of truth to familiarize yourself with some of the considerations to be aware of.
  2. Because you won't be using migrations, there is no need to model sequences, non-primary indexes, constraints and index filters.
  3. An integration test suite is valuable in this approach for validating a proper handoff between code and the database as the code and database evolve.
  4. One approach to test that your mappings are correct is to generate a dummy database using a "throwaway" migration, then use a tool to compare the generated database to the actual database. You can quickly flag differences in schema and act on them.
  5. If you prefer, you can consider generating partial classes from the database and use extensions to those classes to configure your custom code.