Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I just upgraded my MVC4 project to .NET 4.5 and EF5 and started using VS2012. After realizing I needed to set-up auto-migrations in the Package Manager again I ran Enable-Migrations - EnableAutomaticMigrations and received the error

No context type was found in the assembly 'MySolutionName'.

Some Research has said that it has to do with EF5 not enabling prereleases. I ran Install-Package EntityFramework -IncludePrerelease but it said EF5 was already installed (which it was when I installed it through the NuGetmanager earlier without specifying -IncludePrerelease.

Does anyone know what I have to do to enable migrations for my project?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
854 views
Welcome To Ask or Share your Answers For Others

1 Answer

I just had the same problem and found your question while searching for a solution.

I got it working. The problem, for me, was that I initially targeted the .NET 4.0 framework when I added the EF 5 via NuGet. Changing the target framework and then reinstalling EF 5 via NuGet, fixed it. It's also possible (see comments) that just reinstalling EF 5 via NuGet is the solution for you.

I had the following line in the App.config file, notice Version=4.4.0.0:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
</configuration>

So what I did was set the target framework to 4.5 inside the solution configuration and set the supported runtime to 4.5 too (inside the app config).

Old:

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

New:

  <startup>
    <supportedRuntime version="v4.5" sku=".NETFramework,Version=v4.5" />
  </startup>

After that change, I removed EF 5.0 via NuGet and added it again. It gave me the following configSection as result, notice Version=5.0.0.0:

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
</configuration>

After that change, it worked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...