Jan 14, 2013 at 7:52 AM
Edited Jan 14, 2013 at 7:54 AM
I´m new to the EF community, I have being watching the project evolution since their starts, and now I´m thrilled about the opportunity to collaborate since the project became open source.
Currently EF Migrations support is restricted to this two scenarios:
- Extending or changing existing migration operations behavior, inheriting from a concrete generator (like SqlServerMigrationSqlGenerator)
- Creating a Migrator from scratch, when you inherit from
MigrationSqlGenerator, but only for existing MigrationOperation
However, both scenarios fall short, when you want to create new operation types (inheriting from
MigrationOperation), and add then to the migration internal operation list to allow the custom generator to process it.
For example, a user wants to add a new operation for creating views. By extending
DBMigrator he can create a method for adding a new CreateViewOperation:
public abstract class CustomDbMigration
protected void CreateView(string viewName, string table, string columns)
var m = new CreateViewOperation(viewName, string table, string columns);
//Currently this isn't possible
And then he want to proccess this new operation type in his custom generator:
public class CustomMigrationSqlGenerator
//Currently this method is never called
protected virtual void Generate(CreateViewOperation operation)
string createViewSql = "CREATE VIEW " + operation.ViewName" + "AS SELECT " + operation.ColumnsAsString() +
"FROM " + operation.Table ";
I would like to propose creating the internals needed to support the creation of custom operations, so that EF migrations users could add operations as needed.
I´m thinking about making the following changes:
- Make the AddOperation method in DBMigration
protected, to allow adding new operation instances easily. This way you can process them when you add your own
- Change the SqlServerMigrationSqlGenerator and allow to discover
Generate methods in inherited classes. This would make easy to extend existing generators and only add new operations to it.
I would like to hear your thoughts about extension support on EF Migrations, and I´m opened to any implementation proposal that you may have.