我们在单独的类库项目(数据层)中有一个EF 6 Dbcontext和迁移,而不是在主mvc 6项目中。 但是,当我们尝试在项目的第一次运行时调用它时
context.Database.Initialize(false);
我们收到非常奇怪的错误消息
System.IO.FileNotFoundException无法找到文件 ' MyProject.Data.resources'
堆栈追踪:
at System.Reflection.RuntimeAssembly.InternalGetSatelliteAssembly(String name, CultureInfo culture, Version version, Boolean throwOnFileNotFound, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GetSatelliteAssembly(CultureInfo lookForCulture, StackCrawlMark& stackMark)
at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary<String, ResourceSet> localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark)
at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)
at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)
at System.Resources.ResourceManager.GetString(String name)
at System.Data.Entity.Migrations.DbMigrator.GetDefaultSchema(DbMigration migration)
at System.Data.Entity.Migrations.DbMigrator.<GetHistorySchemas>b__6(<>f__AnonymousType10<String, DbMigration> <>h__TransparentIdentifier4)
at System.Linq.Enumerable.<>c__DisplayClass7_0<TSource, TMiddle, TResult>.<CombineSelectors>b__0(TSource x)
at System.Linq.Enumerable.WhereSelectListIterator<TSource, TResult>.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__58<TSource>.MoveNext()
at System.Linq.Enumerable.<ConcatIterator>d__58<TSource>.MoveNext()
at System.Linq.Enumerable.<DistinctIterator>d__63<TSource>.MoveNext()
at System.Linq.Buffer<TElement>..ctor(IEnumerable<TElement> source)
at System.Linq.Enumerable.<ReverseIterator>d__74<TSource>.MoveNext()
at System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey)
at System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey)
at System.Data.Entity.Migrations.History.HistoryRepository.<GetUpgradeOperations>d__16.MoveNext()
at System.Linq.Enumerable.Any<TSource>(IEnumerable<TSource> source)
at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
at System.Data.Entity.Migrations.DbMigrator.<>c__DisplayClassc.<Update>b__b()
at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update()
at System.Data.Entity.MigrateDatabaseToLatestVersion<TContext, TMigrationsConfiguration>.InitializeDatabase(TContext context)
at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf<TContext>.<CreateInitializationAction>b__e()
at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
at System.Data.Entity.Internal.RetryAction<TInput>.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action<InternalContext> action)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Database.Initialize(Boolean force)
at MyProject.Data.DbHelper.SetupDatabase() in E:\Projects\MyProject\src\MyProject.Data\DbHelper.cs:line 29
at MyProject.Business.Services.DatabaseService.SetupDatabase() in E:\Projects\MyProject\src\MyProject.Business\Services\DatabaseService.cs:line 17
at MyProject.Web.Startup.ConfigureServices(IServiceCollection services) in E:\Projects\MyProject\src\MyProject.Web\Startup.cs:line 61
这很奇怪。它在我们尝试在数据项目的App.config中设置连接字符串并从包管理器控制台运行update-database时起作用(但我相信这是因为在这种情况下它的行为就像一个单独的项目)
任何人都能很好地解决这个问题吗?
P.S。其他问题没有回答这个问题,因为从xproj项目访问csproj项目中的迁移是一个问题。
答案 0 :(得分:0)
这是一个已知的dnx问题。它不是迁移问题,而是类库中EF6模型的问题。
答案在这里:Entity Framework 7 error : "EntityFramework.Core.resources" is missing (7.0.0-rc1-final)
将此添加到您的启动配置方法:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//...
var localizationOptions = new RequestLocalizationOptions()
{
SupportedCultures = new List<CultureInfo> { new CultureInfo("") },
SupportedUICultures = new List<CultureInfo> { new CultureInfo("") }
};
var invariantCulture = new RequestCulture(new CultureInfo(""), new CultureInfo(""));
app.UseRequestLocalization(localizationOptions, invariantCulture);
//...
}