Currently, the CSharpMigrationCodeGenerator must have a specific Generate method for each specific MigrationOperation in the migration. If there is a custom MigrationOperation in the list of migrations, it falls back to the Generate method for the AddColumnOperation, which fails with the following exception:
_The best overloaded method match for 'System.Data.Entity.Migrations.Design.CSharpMigrationCodeGenerator.Generate(System.Data.Entity.Migrations.Model.AddColumnOperation, System.Data.Entity.Migrations.Utilities.IndentedTextWriter)' has some invalid arguments_
The CSharpMigrationCodeGenerator should work more like the SqlServerMigrationSqlGenerator, where there is a virtual Generate method for MigrationOperation:
```
protected virtual void Generate(MigrationOperation migrationOperation)
```
As:
```
protected virtual void Generate(MigrationOperation migrationOperation, IndentedTextWriter writer)
```
In this way, developers could override this virtual method when creating a class that derives from CSharpMigrationCodeGenerator the same way it is currently possible with the SqlServerMigrationSqlGenerator class.
Without this, the workaround is to either reimplement the CSharpMigrationCodeGenerator or skip the code migration step for custom migration operations and translate each into a SqlOperation.
As a side note, since there is already a GetDefaultNamespaces virtual method, we can register any custom namespaces required to support the custom MigrationOperation types, so there is no issue with the migration class being generated with broken references.
-- Travis Schettler
_The best overloaded method match for 'System.Data.Entity.Migrations.Design.CSharpMigrationCodeGenerator.Generate(System.Data.Entity.Migrations.Model.AddColumnOperation, System.Data.Entity.Migrations.Utilities.IndentedTextWriter)' has some invalid arguments_
The CSharpMigrationCodeGenerator should work more like the SqlServerMigrationSqlGenerator, where there is a virtual Generate method for MigrationOperation:
```
protected virtual void Generate(MigrationOperation migrationOperation)
```
As:
```
protected virtual void Generate(MigrationOperation migrationOperation, IndentedTextWriter writer)
```
In this way, developers could override this virtual method when creating a class that derives from CSharpMigrationCodeGenerator the same way it is currently possible with the SqlServerMigrationSqlGenerator class.
Without this, the workaround is to either reimplement the CSharpMigrationCodeGenerator or skip the code migration step for custom migration operations and translate each into a SqlOperation.
As a side note, since there is already a GetDefaultNamespaces virtual method, we can register any custom namespaces required to support the custom MigrationOperation types, so there is no issue with the migration class being generated with broken references.
-- Travis Schettler