8

I've recently upgraded a WFC project that uses Entity Framework from v4.3.1 to 5.0.
I'm running Coded migrations only (no automatic migrations).

Previously, I was using the Publish Profiles to deploy this solution and apply the migrations. Since upgrading the project to EF5, the migrations portion no longer works and the publish dialog doesn't detect the context as having code-first migrations.

Specifically, the .pubxmlfile changed from detecting my context as <Object Type="DbCodeFirst">to <Object type="DbDacFx"> which is incorrect for my context.

As a workaround, I've manually added the <entityFramework> database initializer configuration to my web.config transforms, but I'd like to understand why the publish profiles aren't working. That was a much nicer solution.

Josh
  • 2,740
  • 3
  • 27
  • 41
  • Take a look at [this](http://stackoverflow.com/questions/16543229/publish-entity-framework-code-first-migrations-with-no-context-in-the-startup-pr/16558527#16558527) post. Maybe it can help you... – Liel May 15 '13 at 12:13

4 Answers4

2

It once happened on me when merging another developer's commit and triggered Visual Studio project reload. That's how it caused the "DbCodeFirst" to "DbDacFx" change.

If I restart Visual Studio then everything goes back to what it should be.

Just another thought.

Xinan
  • 3,002
  • 1
  • 16
  • 18
  • It is too bad that @josh didn't mark this as the answer, other than up-voting I can only offer you my gratitude, this saved my day, literally – Luis Ferrao Dec 13 '16 at 14:42
0

You probably missed adding the reference to EntityFramework into your project. By just adding the reference you should be able to control whether or not the DbCodeFirst option is available or not.

0

As this post suggests, try using the fully-qualified name of your DbContext as the name of the connection string. Instead of:

Web.config

<connectionStrings> <add name="MyContext" .../> </connectionStrings>

Use:

Web.config

<connectionStrings> <add name="MyNamespace.AnotherNamespace.MyContext" .../> </connectionStrings>

In my case, in order to use my existing publish profiles (.pubxml), I also had to manually edit the <ObjectGroup Name="..." ...>. Probably recreating the publish profiles would work too.

Community
  • 1
  • 1
Carl G
  • 17,394
  • 14
  • 91
  • 115
0

I had the same issue but not in the same context.

I had been using Code First Migrations with existing ASP.NET MVC 5.2.3 application using EF 6.1.3 for a month without issues. At one point in time I added support for Windows Azure Storage but I made some mistakes:

  • I added a new project. Unfortunately I chose "Console Application" instead of "Class Library". I tried to fix it by changing it back to "Class Library" in "Project Settings"
  • I used Nuget to Install-Package WindowsAzure.Storage but I installed it on the MVC project and not on the class library. I tried to fix it by doing Uninstall-Package on the MVC project and installing it to the correct project
  • I called the class in the class library "WorkOrderStorage"
  • I added the connectionString to <connectionStrings> element in web.config and a transformation in web.release.config

I guess my project was now in an inconsistent state. I noticed that it would forget about Code First Migrations (I monitored the changes to the .pubxml file):

  1. when I put a reference between the MVC project and the library containing the WorkOrderStorage class
  2. when I created an empty 'WorkOrderStorage' class in one of the existing libraries

In the end I fixed it by recreating this library correctly from scratch as a class library (because of observation 1). I also named the class WorkOrderRepository (because of observation 2).

Bart Jolling
  • 595
  • 6
  • 21