1

There are two EF7 db-contexts in a MVC6 (beta-7) project. First of them (let's call it StartupContext) is in a startup project (MyProject.Startup). Second (let's call it DataContext) is in a separate assembly (MyProject.Data).

There is a command in the project.json files of the MyProject.Startup and the MyProject.Data:

"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:

    dnx ef database update

  • for an updating of the DataContext I run the ef command from a folder of the MyProject.Data project:

    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:

System.IO.FileNotFoundException: Could not load file or assembly "MyProject.Data" or one of its dependencies.

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.

Has anybody else had a similar problem?

How can I update a database and create a migration from a published project?

hcp
  • 3,268
  • 6
  • 26
  • 41
  • Make sure that your target framework is the right one (for example, `clr` instead of `coreclr`) – Leonardo Herrera Oct 13 '15 at 18:46
  • @LeonardoHerrera I am sure, I use the Clr framework in all my projects. – hcp Oct 13 '15 at 19:20
  • What does `dnvm list` tells you? Is the right version selected there? I found out that (in order to publish to Azure) I had to have everything lined up. – Leonardo Herrera Oct 13 '15 at 19:57
  • @hypercodeplace How are you creating the published project? – Stafford Williams Oct 13 '15 at 23:59
  • @LeonardoHerrera there is only `dnx-clr-win-x64.1.0.0-beta7` And it is used as standard. – hcp Oct 14 '15 at 14:16
  • @StaffordWilliams I created the published project by the Publish WIzard of Visual Studio 2015. – hcp Oct 14 '15 at 14:17
  • Do you have an intermediate directory where the published project is located? If so, does `dnu build` work there? – Leonardo Herrera Oct 14 '15 at 14:31
  • @LeonardoHerrera It seems it doesn't work. My command is `@"%~dp0approot\runtimes\dnx-clr-win-x64.1.0.0-beta7\bin\dnx.exe" dnu build`. There is the `System.InvalidOperationException. Unable to resolve project "Release"` exception. The intermediate directory (a folder with published solution) names `C:\Release`. – hcp Oct 14 '15 at 14:45
  • 1
    Note that Visual Studio always uses x86 version of DNX (for now I think). You may check it in output window under 'Package Manager' pane. If you need x64 version you may need to build it on your own using `dnu restore`, `dnu build` or line up versions with VS using `dnvm use` as @LeonardoHerrera mentioned. – pg0xC Oct 14 '15 at 15:18
  • I note when I applied all migrations and updated database from sources directory (using a path to the battle db) project works perfectly from intermediate directory (launch it by the `dnx web` command). Therefore I think a framework doesn't affect on succfully db updating. – hcp Oct 14 '15 at 15:30
  • I've observed that there is some disconnection on the dnu commands and Visual Studio. I assume that `dnx web` also doesn't work in your published directory. Anyways, check [this SO question](http://stackoverflow.com/questions/29973153/run-asp-net-5-mvc-6-using-net-core-on-iis) on publishing x64 projects. – Leonardo Herrera Oct 14 '15 at 15:51

1 Answers1

1

This is a bug in EF7-beta7 and should be fixed in the upcoming RC1 release of EF.

If you need (as in very much so) this feature before the, you could use the nightly builds of EF. (Caution: nightly builds have a lot of instability.)

natemcmaster
  • 25,673
  • 6
  • 78
  • 100