升级到 .NET 4.5 和 EF 5 后“启用迁移"失败

编程入门 行业动态 更新时间:2024-10-15 22:27:11
本文介绍了升级到 .NET 4.5 和 EF 5 后“启用迁移"失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我刚刚将我的 MVC4 项目升级到 .NET 4.5 和 EF5 并开始使用 VS2012.在意识到我需要再次在包管理器中设置自动迁移后,我运行 Enable-Migrations - EnableAutomaticMigrations 并收到错误

在程序集MySolutionName"中找不到上下文类型.

一些研究表示这与 EF5 不启用有关预发行.我运行了 Install-Package EntityFramework -IncludePrerelease 但它说 EF5 已经安装(这是我之前通过 NuGetmanager 安装它时没有指定-IncludePrerelease.

有人知道我必须做什么才能为我的项目启用迁移吗?

解决方案

我刚遇到同样的问题,在寻找解决方案时发现了您的问题.

我成功了.对我而言,问题在于我最初通过 NuGet 添加 EF 5 时针对 .NET 4.0 框架.更改目标框架,然后通过 NuGet 重新安装 EF 5,修复了它.也有可能(请参阅评论)通过 NuGet 重新安装 EF 5 就是适合您的解决方案.

我在 App.config 文件中有以下行,注意 Version=4.4.0.0:

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

所以我所做的是在解决方案配置中将目标框架设置为 4.5,并将支持的运行时也设置为 4.5(在应用程序配置中).

旧:

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

新:

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

在那次更改之后,我通过 NuGet 删除了 EF 5.0 并再次添加了它.结果它给了我以下 configSection,注意 Version=5.0.0.0:

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

在那次更改之后,它起作用了.

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?

解决方案

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.

更多推荐

升级到 .NET 4.5 和 EF 5 后“启用迁移"失败

本文发布于:2023-11-16 23:03:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607860.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:升级到   NET   EF   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!