EF Code First Migration with Multiple Database / DbContext

后端 未结 3 1185
孤城傲影
孤城傲影 2020-12-29 00:04

I have two database each with their own dbcontext. I\'ve setup two migration configurations. I can add a migration for the first db ust fine (Add-Migration DB1_Initial

相关标签:
3条回答
  • 2020-12-29 00:51

    I've been able to answer my own question. My two configuration classes existed in the same namespace. As soon as I separated them, everything worked.

    0 讨论(0)
  • 2020-12-29 01:03

    With Entity Framework 6 it's easy.

    It's the same procedure for both multiple DbContexts for one database and for multiple DbContexts for each their own database:

    Enable-Migrations -ContextTypeName <DbContext-Name-with-Namespaces> -MigrationsDirectory:<Migrations-Directory-Name>

    Add-Migration -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces> <Migrations-Name>

    Update-Database -configuration <DbContext-Migrations-Configuration-Class-with-Namespaces> -Verbose

    Source

    0 讨论(0)
  • 2020-12-29 01:05

    It's been a while, but this could be a better answer to your problem :)

    Update-Database -ConfigurationTypeName "SlaveConfiguration"
                    -StartupProjectName "FacturatieMVCv2.Data" -Verbose 
                    -ConnectionString "connstring;" 
                    -ConnectionProviderName "System.Data.SqlClient"
    
    0 讨论(0)
提交回复
热议问题