EF6: renaming a namespace using the first code migrations

Is it possible to rename the namespace of my entire project (including, of course, the DbContext class, migration configuration classes, etc.) without breaking anything or re-creating all my migrations?

Say I have a Project MyProject whose namespace is

Foo.MyProject 

And my configuration classes are in

 Foo.MyProject.Migrations 

Let's say I want to rename the Foo namespace to Bar , and of course the Configurations namespace will now be

 Bar.MyProject.Configurations 

Is there a proper way to do this and support all my current migrations? These methods include manually editing the ___MigrationHistory table or something else? (At a glance, I see a ContextKey column, which I suspect must manually edit.)

+6
source share
1 answer

Yes, you really need to update the ContextKey in the__MigrationHistory table. Code:

 UPDATE [dbo].[__MigrationHistory] SET [ContextKey] = 'New_Namespace.Migrations.Configuration' WHERE [ContextKey] = 'Old_Namespace.Migrations.Configuration' 

Read well on the topic of renaming namespaces with EF6:

http://jameschambers.com/2014/02/changing-the-namespace-with-entity-framework-6-0-code-first-databases/

+11
source

All Articles