EntityFramework6.Npgsql
EntityFramework6.Npgsql copied to clipboard
Unhandled MigrationOperation
From @lordscarlet on July 13, 2014 14:15
First off, I am using v2.2.0.
I have created a MigrationOperation in order to add a full text index. However, it seems that the way the NpgsqlMigrationSqlGenerator is setup, you cannot add any new operations. Specifically, this code (I believe) will make it so that I can never add my own operation:
else
{
if (!(migrationOperation is UpdateDatabaseOperation))
throw new NotImplementedException("Unhandled MigrationOperation " + migrationOperation.GetType().Name + " in " + this.GetType().Name);
this.Convert((migrationOperation as UpdateDatabaseOperation).Migrations as IEnumerable<MigrationOperation>);
}
From what I can tell, this means that if I have made my own migration operation, an error will always be thrown. Is this intended? Or am I perhaps implementing my operation in the wrong way? I pretty much followed http://romiller.com/2013/02/27/ef6-writing-your-own-code-first-migration-operations/, but with the creation of an index instead. The most notable difference in my setup is a change in configuration:
SetSqlGenerator("NpgSql", new PabloSqlServerMigrationSqlGenerator());
One other item of note, I am inheriting SqlServerMigrationSqlGenerator in my generator, because anything of value in NpgsqlMigrationSqlGenerator is private (AddStatement(), AppendTableName(), migrationStatements, etc), but as far as I can tell that shouldn't matter as long as NpgsqlMigrationSqlGenerator did not throw an unnecessary error.
Copied from original issue: npgsql/npgsql#276
From @DavidKarlas on July 13, 2014 14:57
I'm not sure where version v2.2.0 came from since there is no NuGet package, Tag or Release... But on master this code looks like this: https://github.com/npgsql/Npgsql/blob/master/Npgsql.EntityFramework/NpgsqlMigrationSqlGenerator.cs#L122-L133
Or am I missing something? Can you try with master?
From @lordscarlet on July 14, 2014 13:23
Yes, I am running off a version of Master. It may be slightly old, but what you linked to has the same problem -- I can never run my own migration because it throws a NotImplementedException
From @DavidKarlas on July 14, 2014 13:42
I'm not sure how this is suppost to work and don't have time atm to look into it... About (AddStatement(), AppendTableName(), migrationStatements, etc) which is public/protected in SqlServerMigrationSqlGenerator you can make PR to make it public/protected in NpgsqlMigrationSqlGenerator. Be careful about those methods because have different behaviour in MsSql and Npgsql...
From @lordscarlet on July 17, 2014 20:59
I am trying to load master to work with it (the version in my project was built by someone else), but I'm having issues.
I am using Visual Studio 2013 and loading the Npgsql2013.sln. Two problems:
- NpgsqlIDdexProvider2013 will not load because it says "This project is incompatible with the current edition of Visual Studio"
- I am getting conflicts with the EntityFramework dll between the nuget pacakage and what is in my v4.5 installation and I have yet to find a work-around for this problem.
The type 'System.ComponentModel.DataAnnotations.Schema.DatabaseGeneratedAttribute' exists in both 'c:\applications\Npgsql\packages\EntityFramework.6.1.1\lib\net40\EntityFramework.dll' and 'c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.ComponentModel.DataAnnotations.dll'
From @lordscarlet on July 17, 2014 21:8
I fixed the second item by removing System.ComponentModel.DataAnnotations from the list of references.
From @lordscarlet on July 18, 2014 16:50
I was able to get around my creation of a custom operation by changing https://github.com/npgsql/Npgsql/blob/master/Npgsql.EntityFramework/NpgsqlMigrationSqlGenerator.cs#L130-L132 to
else
{
Convert((dynamic)migrationOperation);
}
But I don't know if that is the sort of implementation you would like, or how gracefully it would handle an unknown operation. It seems to me, however, that by not allowing custom operations as the code currently stands, you're greatly limiting the intended functionality of migrations.
Thoughts?
From @lordscarlet on July 18, 2014 16:53
It also seems like that whole method could be simplified to this if statement, but it is possible I am missing something.
if (migrationOperation is SqlOperation)
{
AddStatment((migrationOperation as SqlOperation).Sql, (migrationOperation as SqlOperation).SuppressTransaction);
}
else if (migrationOperation is UpdateDatabaseOperation)
{
Convert((migrationOperation as UpdateDatabaseOperation).Migrations as IEnumerable<MigrationOperation>);
}
else
{
Convert((dynamic)migrationOperation);
}
From @lordscarlet on July 18, 2014 20:23
I was mistaken, there needs to be more done. Probably revealing the migrationstatements and/or some methods.
Should I keep down this track and commit a PR, or are you against the approach?
From @DavidKarlas on July 18, 2014 21:4
Ofcourse... If it solves your problem and is not a hack and you add few unit tests I'm sure it will be accepted... Why not...
From @lordscarlet on July 18, 2014 21:8
Ok, thanks. There's still something I'm not fully understanding about custom migrations, so my solution isn't 100%. I will submit a PR when it is.
From @franciscojunior on July 19, 2014 22:27
Thanks @lordscarlet ! We will review your patch.
I'm going over old issues and this one appeared to have slipped through the cracks...
I'm interested in understanding the exact problem this seeks to resolve: what kind of custom migration operations do people need? Is EF6 meant to support custom user-implemented operations in this way?
Regardless, the practice of using dynamic
to execute the correct overload (instead of many ifs) seems OK to me, and is used inside core EF7 code.
@lordscarlet, any chance you're still interested in this?
From @lordscarlet on August 11, 2015 0:42
@roji unfortunately I have been massively distracted from the project this is for. But, let me just say why I need this. It was simply to be able to create a migration that created (or of course removed) a full text index.
No problem @lordscarlet, thanks for the info. We'll try to take a look at this at some point.
@lordscarlet any more interest in pursuing this? If not I'll close...
I got this error when invoking the CreateStoredProcedure
in my DbMigration
file. The fix was to add the stored procedure using the raw Sql
method.