asp.net-mvc - 未找到类型 'System.Data.Entity.Infrastructure.SqlConnectionFactory' 的构造函数

标签 asp.net-mvc entity-framework windows-8 visual-studio-2012 entity-framework-5

昨天我将我的电脑从 Windows 7“升级”到了 Windows 8,所以现在我使用 Visual Studio 2012,并打开我的 Visual Studio 2010 项目。

这个项目总是工作正常,但它在 Visual Studio 2012 中不起作用。我遇到了一些奇怪的错误,但我修复了这些错误。现在我只剩下一个错误,我无法修复该错误,并且在 Google 上找不到任何相关内容:

我得到这个异常:

Failed to set Database.DefaultConnectionFactory to an instance of the 'System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework' type as specified in the application configuration. See inner exception for details.

具有以下内部异常:

Constructor on type 'System.Data.Entity.Infrastructure.SqlConnectionFactory' not found.

我的 Web.Config 看起来很标准:

  <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-WebUI-201253192737;Integrated Security=True" providerName="System.Data.SqlClient" />
  </connectionStrings>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>

SqlConnectionFactory 类存在,它有 2 个构造函数(一个无参数,一个采用连接字符串)。我通过在 C# 代码中创建 SqlConnectionFactory 进行了测试。

我已经删除了 Entity Framework 并重新安装了它,但这并没有解决问题。

我正在使用 Entity Framework 5.0 RC(如前所述,它在 VS2010 中运行良好)以及 SQL Server 2012 + 工具和 IIS Express。

最佳答案

我解决了这个问题。我改变了这个:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="Data Source=.\SQLEXPRESS; Integrated Security=True; MultipleActiveResultSets=True" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>

致:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
  </entityFramework>

现在可以了。虽然有点愚蠢,但我想提供连接字符串作为参数。

我通过在 VS 2012 中使用 Entity Framework 创建一个新的 MVC 4 项目并比较 Web.Config 文件发现了这一点。我注意到另一个区别。

我的 Entity Framework 程序集的版本为 4.4.0.0(尽管我从 NuGet 安装了 5.0 RC)。我创建的新项目有一个版本为 5.0.0.0 的程序集。谁能解释一下吗?

关于asp.net-mvc - 未找到类型 'System.Data.Entity.Infrastructure.SqlConnectionFactory' 的构造函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10965210/

相关文章:

c# - 有没有一种快速的方法来获得两个实体之间的每一个关联?

asp.net-mvc - Nop Commerce 中的流畅验证 - 仅限字母数字

javascript - 我可以设置总页数并在单击下一页时使用 jq 网格中的 ajax 加载下一组记录吗?

c# - ASP.NET MVC razor View ,发布到与原始模型绑定(bind)不同的模型?

entity-framework - DbContext 和 EF Code First 的更改跟踪差异

windows-8 - 我可以将我的 Windows Phone 和 Windows 8 应用程序从一个帐户转移到另一个帐户吗?

c# - 使用 Html.Action() 时,PartialView ViewBag 数据在父 View 中不可用

c# - 模拟新的 Microsoft Entity Framework Identity UserManager 和 RoleManager

button - 单击按钮时添加下拉菜单 - Windows 8

c# - Metro 风格应用程序中缺少 .NET 功能?