简体   繁体   English

如何设置启动项目以更新已发布的 ASP.NET5 中的数据库 | MVC6项目?

[英]How to set a startup project to update a database in a published ASP.NET5 | MVC6 project?

There are two EF7 db-contexts in a MVC6 (beta-7) project. MVC6 (beta-7)项目中有两个EF7 db-contexts。 First of them (let's call it StartupContext ) is in a startup project ( MyProject.Startup ).首先(我们称之为StartupContext )在一个启动项目( MyProject.Startup )中。 Second (let's call it DataContext ) is in a separate assembly ( MyProject.Data ).第二个(我们称之为DataContext )在一个单独的程序集( MyProject.Data )中。

There is a command in the project.json files of the MyProject.Startup and the MyProject.Data : MyProject.StartupMyProject.Dataproject.json文件中有一个命令:

"dependencies": {
  "EntityFramework.SqlServer": "7.0.0-beta7",
  "EntityFramework.Commands": "7.0.0-beta7",
  ...
}

"commands": {
  "ef": "EntityFramework.Commands"
  ...
}

I can use it for a database updating like this:我可以用它来更新这样的数据库:

  • for an updating of the StartupContext I run the ef command from a startup folder:为了更新StartupContext我从启动文件夹运行ef命令:

    dnx ef database update

  • for an updating of the DataContext I run the ef command from a folder of the MyProject.Data project:为了更新DataContext我从MyProject.Data项目的文件夹中运行ef命令:

    dnx ef database update -c DataContext -s MyProject.Startup

It works perfectly but only from sources (from not published project).它可以完美运行,但只能来自来源(来自未发布的项目)。 I get exception like this for an updating of the DataContext from a published project:从已发布的项目中更新DataContext ,我得到了这样的异常:

System.IO.FileNotFoundException: Could not load file or assembly "MyProject.Data" or one of its dependencies. System.IO.FileNotFoundException:无法加载文件或程序集“MyProject.Data”或其依赖项之一。

I tried various approaches:我尝试了各种方法:

dnx ef database update -c DataContext -s MyProject.Startup
dnx ef database update -c DataContext -s C:\Published\approot\packages\MyProject.Startup
dnx ef database update -c DataContext -s C:\Published\approot\packages\MyProject.Startup\1.0.0\root\
dnx ef database update -c DataContext -s C:\Published\approot\packages\MyProject.Startup\1.0.0\lib\MyProject.Startup.dll
dnx ef database update -c DataContext -s %~dp0approot\packages\MyProject.Startup
dnx ef database update -c DataContext -s %~dp0approot\packages\MyProject.Startup\1.0.0\root\

I also tried to copy the MyProject.Startup.dll to a folder with the MyProject.Data but unsuccessfully.我也试图复制MyProject.Startup.dll与文件夹MyProject.Data ,但没有成功。

Has anybody else had a similar problem?有没有其他人遇到过类似的问题?

How can I update a database and create a migration from a published project?如何更新数据库并从已发布的项目创建迁移?

This is a bug in EF7-beta7 and should be fixed in the upcoming RC1 release of EF.这是 EF7-beta7 中的一个错误,应该在即将发布的 EF RC1 版本中修复。

If you need (as in very much so) this feature before the, you could use the nightly builds of EF.如果您需要(非常需要)此功能,您可以使用 EF 的夜间构建。 (Caution: nightly builds have a lot of instability.) (注意:夜间构建有很多不稳定性。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM