The EF7 migration add
command (to date, beta5) compares the model classes defined in the DbContext
against the current model snapshot, creates a new migration class, and updates the model snapshot.
I need to modify the migration to make it generate different DDL SQL. As an example, EF7 uses sequences for SQL Server auto-increment values, and I would like it to use identity. However it could be any other reason. The migration remove
command would physically delete the migration files and revert the model snapshot, so it's useless in this case.
There are 3 files that contain related code that look like they need to be edited:
- The primary migration class: The
Up
andDown
methods should be modified. - The
DbContextModelSnapshot
file contains Annotations that need to be modified - The secondary migration partial class: The badly named
[migration].Designer.cs
file also contains a model snapshot for the migration. I'm assuming this snapshot needs to match the model snapshot in item 2, but am not certain. The only information I have about the purpose of it is from Brice's blog , which says "It’s there in case you or a provider need to inspect the model for additional information during a migration."
Specific questions:
- Do the two model snapshots need to be kept in sync in order to correctly perform migrations?
- Is modifying 3 separate files the only way to edit the migration? (Although depending on the changes, the model snapshots may not have to be touched in some cases.)
- Is there some EF command that would regenerate just the model snapshots, but not the migration methods?