Entity Framework uses a set of conventions to build a model based on the shape of your entity classes. You can specify additional configuration to supplement and/or override what was discovered by convention.
EF Core provides two primary ways of keeping your EF Core model and database schema in sync. To choose between the two, decide whether your EF Core model or the database schema is the source of truth.
If you want your EF Core model to be the source of truth, use Migrations. As you make changes to your EF Core model, this approach incrementally applies the corresponding schema changes to your database so that it remains compatible with your EF Core model.
Use Reverse Engineering if you want your database schema to be the source of truth. This approach allows you to scaffold a DbContext and the entity type classes by reverse engineering your database schema into an EF Core model.
I originally thought that an EF Core model is some entity classes in C#. But the above two quotes seem to suggest an EF Core model is something sitting between the entity classes and the database.
So I was wondering whether a EF Core model is represented as part of a C# .NET Core program? I don't have Visual Studio IDE, and I can only sense its existence as some part of the program.
But the above two quotes seem to suggest an EF Core model is something sitting between the entity classes and the database.
Yes - and no.
Internally, Entity Framework (both EF6 and EF Core) have a "database model" which is internal to EF and programmers have no access to (unless they poke around the internals). This model is not represented by POCO or "entity objects" but by an internal system which we (as consumers of EF) don't interact with (so it doesn't matter).
In older versions of Entity Framework this was the
*.edmx XML file which lists all of the database tables, columns, sprocs, UDFs, etc and maps them to .NET class types and their members. This is the internal database model it's referring to.
Recent versions of EF (including EF Core) do-away with this EDMX file. The internal database model still exists, it's just generated at runtime (using the
Configuration code) instead of using the
For more details, I recommend this StackOverflow QA from 2012 that's referring to Entity Framework 4's 3 different "modes" (Code-first, Database-first, and Model-first). EF Core is now technically only Code-first, but "Database-first" is accomplished by regenerating the POCO and
Configuration code from a real-life SQL Server database (or other supported RDBMS).