0

我有一個MVC 4項目(Company.Project.WebUI),一個用於我所有模型類(Company.Project.Data)的項目和一個DAL項目(Company.Project。服務)。實體框架中的不同dll代碼首先遷移

我該如何使用Code First Migrations來管理這個問題?

我收到以下錯誤,當我寫的命令Add-Migration Init

`

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. 
    at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) 
    at System.Reflection.RuntimeModule.GetTypes() 
    at System.Reflection.Assembly.GetTypes() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 

`

當我寫的命令Add-Migration -StartUpProjectName "Company.Project.Services" Init我也得到一個錯誤

`

System.IO.FileNotFoundException: Could not load file or assembly 'Company.Project.WebUI' or one of its dependencies. The system cannot find the file specified. 
File name: 'Company.Project.WebUI' 
    at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
    at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) 
    at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) 
    at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) 
    at System.Reflection.Assembly.Load(String assemblyString) 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore() 
    at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run() 

`

有人能告訴我使用EF Code First Migration與不同dll的最佳方式是什麼?

回答

0

我不知道爲什麼,但EF希望您的DAL項目被設置爲Visual Studio中的啓動項目。我只是有同樣的錯誤,這解決了這個問題。

解決方案資源管理器:右鍵單擊您的DAL項目 - >選擇「設置爲啓動項目」。