Elk van hen heeft een heel ander doel:
OnModelCreating is used for inline fluent-API definitions of your model. These definitions together with default conventions, data annotations and configuration classes forms the complete definition of the model.
- Explicit migration defines what must be done to database to migrate it to the form required by your current model
Now, how those two relate? Migration has two inputs which are used to generate migration code (
Down methods). One input is the last migration record stored in
__MigrationHistory table in the database. This record contains serialized model representing the database. This input is optional because first migration must work without it. The second input is mandatory - it is your current model which is retrieved by executing the code in your current assembly =>
Add-Migration will execute your
OnModelCreating to get the current model and compare it with the model retrieved from the database. The result of comparison is content of
Down methods in the explicit migration.