我有两个上下文和一个数据库。
当我尝试添加数据库迁移(add-migrations)时,我收到此错误。
我已将EF更新为6.2。
我检查过,configure.cs文件正在使用
internal sealed class Configuration : DbMigrationsConfiguration<MSiH.CigaretteContext>
PM&GT; add-migration -configuration MSiH.DataAccess.CigaretteContext -Verbose cmdlet在命令管道位置1处添加迁移 提供以下参数的值: 名称:初始 使用StartUp项目'GridAndMap'。 使用NuGet项目'GridAndMap'。
System.Data.Entity.Migrations.Infrastructure.MigrationsException: The type
'MSiH.CigaretteContext' does not inherit from
'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
Migrations configuration types must extend from
'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
at System.Data.Entity.Utilities.TypeExtensions.CreateInstance[T]
(Type type, Func`3 typeMessageFactory, Func`2 exceptionFactory)
at System.Data.Entity.Migrations.Utilities.MigrationsConfigurationFinder.FindMigrationsConfiguration
(Type contextType, String configurationTypeName,
Func`2 noType, Func`3 multipleTypes, Func`3 noTypeWithName, Func`3 multipleTypesWithName)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
at System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.Execute(String name, Boolean force, Boolean ignoreChanges)
at System.Data.Entity.Migrations.AddMigrationCommand.<>c__DisplayClass2.<.ctor>b__0()
at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
The type 'MSiH.EyePaid.CigaretteWebApp.DataAccess.CigaretteContext' does not inherit
from 'System.Data.Entity.Migrations.DbMigrationsConfiguration'. Migrations
configuration types must extend from
'System.Data.Entity.Migrations.DbMigrationsConfiguration'.
更新
关于如何在多个上下文中使用EF Migration,我正在关注example。
Enable-Migrations -ContextTypeName Foo.CigaretteContext
此命令出错:
Add-Migration -configuration Foo.CigaretteContext Initial
此命令有效:
Add-Migration Initial
答案 0 :(得分:5)
Configuration
或ConfigurationTypeName
参数是指从DbMigrationsConfiguration派生的类。
您所做的是指从DbContext
派生的类。
你应该这样做。
Add-Migration -Configuration MSiH.MigrationDatabaseIfAny.Configuration Initial
PS:MigrationDatabaseIfAny
是目录名称如果您的Configuration
类位于目录下,如果不是只删除它。