EF6: Renaming namespace using Code First Migrations

前端 未结 1 619
后悔当初
后悔当初 2020-12-29 09:36

It is possible for me to rename the namespace of my entire Project (including of course: DbContext class, Migrations configuration classes, etc) without breaking anything o

相关标签:
1条回答
  • 2020-12-29 10:07

    Yes, you do indeed 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'
    

    A good read on the topic of renaming namespaces with EF6:

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

    0 讨论(0)
提交回复
热议问题