如果您在 EF 存储库中搜索此错误消息(“未找到迁移配置类型”),您将在 EntityFramework/Properties/Resources.cs 文件中找到此资源:
/// <summary>
/// A string like "No migrations configuration type was found in the assembly '{0}'. (In Visual Studio you can use the Enable-Migrations command from Package Manager Console to add a migrations configuration)."
/// </summary>
internal static string AssemblyMigrator_NoConfiguration(object p0)
{
return EntityRes.GetString(EntityRes.AssemblyMigrator_NoConfiguration, p0);
}
下一步是搜索AssemblyMigrator_NoConfiguration
使用情况,您会发现只有一个出现在 EntityFramework/Migrations/Design/ToolingFacade.cs 中:
private DbMigrationsConfiguration FindConfiguration()
{
var configurationType = FindType<DbMigrationsConfiguration>(
ConfigurationTypeName,
types => types
.Where(
t => t.GetConstructor(Type.EmptyTypes) != null
&& !t.IsAbstract
&& !t.IsGenericType)
.ToList(),
Error.AssemblyMigrator_NoConfiguration,
(assembly, types) => Error.AssemblyMigrator_MultipleConfigurations(assembly),
Error.AssemblyMigrator_NoConfigurationWithName,
Error.AssemblyMigrator_MultipleConfigurationsWithName);
return configurationType.CreateInstance<DbMigrationsConfiguration>(
Strings.CreateInstance_BadMigrationsConfigurationType,
s => new MigrationsException(s));
}
我认为现在跟踪错误并修复它会更容易。
我已经在源代码上对其进行了测试,并且消息无关紧要,结果发现 rel 原因是 app.config 中的目标框架标签。
这是正确答案的类似问题:
“Enable-Migrations”在升级到 .NET 4.5 和 EF 5 后失败
有趣的是,如果您运行 Enable-Mirations 和 Add-Migration 分别准确地指向 Context 类名和 Configuratin 类名,它工作正常。但是提到的解决方案是正确的解决方案,也更容易:-)