EF Migrations: Add extension support for new operations

Topics: EF Runtime
Jan 14, 2013 at 7:52 AM
Edited Jan 14, 2013 at 7:54 AM

Hi all, 

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 types.

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
        : DbMigration
        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
        : SqlServerMigrationSqlGenerator
        //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 MigrationSqlGenerator.
  • 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.

Jan 14, 2013 at 5:05 PM
Edited Jan 14, 2013 at 5:47 PM


Thanks for considering contributing to EF!

The changes you propose make perfect sense and I'm pretty sure we would take them in the core.

In case you haven't seen it, here is our page on contributing.



Jan 14, 2013 at 11:01 PM

Hi Andrew,


Thanks to you for your quick response.

I just was reading about contributing, and I´m not sure what is the next step. Should I open an Issue/Feature request first? 

Looking forward to start coding!


Iñaki Elcoro.

Jan 15, 2013 at 6:46 PM

Hi Iñaki,

I found this existing work item tracking this.

The main thing you need to sort out is the Contributor License Agreement (CLA) because we can't consider any contributions until that is taken care of.



Jan 15, 2013 at 8:24 PM

Seems like that issue fits almost perfectly with this. great!

As for the CLA I'm going to sent it inmediately.


Iñaki Elcoro
Jan 16, 2013 at 10:23 PM

I sended the CLA yesterday,

I´m waiting to receive the answer.




Jan 20, 2013 at 11:43 AM



I didn't receive any answer about the CLA yet, is normal to take it so long?



Jan 21, 2013 at 6:19 PM


I believe you have a response from our legal team as they are processing your CLA, let me know if they haven't received that and I will follow up with them again.

We only need the CLA to be finalized when it comes time for us to review your code, so feel free to start discussing, coding etc. in the meantime.


Jan 21, 2013 at 7:36 PM
Edited Feb 3, 2013 at 10:55 PM
You are right, I have received the response just today. I will correct the issues tomorrow, meanwhile my only question is how do I associate this with the already opened work item after the code is reviewed. Thank you!
Jan 21, 2013 at 10:00 PM


Our team will take care of submitting the code and linking the changeset to the appropriate issue once you've submitted a pull request. For the moment just post a comment on the issue that you are starting work on it, probably best to include a link to this discussion as well.


Feb 3, 2013 at 11:04 PM

Just wanted to annouce that finally I got sometime to work on this, and here is the pull request

Any comments are very welcome.