找不到类型'System.Data.Entity.Infrastructure.SqlConnectionFactory'的构造方法 [英] Constructor on type 'System.Data.Entity.Infrastructure.SqlConnectionFactory' not found

查看:228
本文介绍了找不到类型'System.Data.Entity.Infrastructure.SqlConnectionFactory'的构造方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我将PC从Windows 7升级"到Windows 8,所以现在我在使用Visual Studio 2012,并打开Visual Studio 2010项目.

I "upgraded" my PC from Windows 7 to Windows 8 yesterday, so now I'm using Visual Studio 2012, and opening my Visual Studio 2010 project.

该项目始终运行良好,但在Visual Studio 2012中不起作用.我有一些奇怪的错误,但我已将其修复.现在,我只遇到一个错误,我无法修复并且无法在Google上找到任何有关的信息:

This project always worked fine, but it doesn't work in Visual Studio 2012. I had some weird errors, but I fixed those. Now I'm left with one error that I just can't fix and can't find anything about on Google:

我收到此异常:

无法将Database.DefaultConnectionFactory设置为应用程序配置中指定的'System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework'类型的实例.有关详细信息,请参见内部异常.

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.

具有以下内部异常:

找不到类型为'System.Data.Entity.Infrastructure.SqlConnectionFactory'的构造函数.

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

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

My Web.Config looks pretty standard:

  <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进行了测试.

The SqlConnectionFactory class exists and it has 2 constructors (one parameterless, and one that takes a connection string). I tested that by creating a SqlConnectionFactory in my C# code.

我已经删除了Entity Framework并重新安装了它,但这并不能解决问题.

I already deleted Entity Framework and reinstalled it, but that didn't solve the problem.

我正在使用带有SQL Server 2012 +工具和IIS express的Entity Framework 5.0 RC(如前所述,它在VS2010中运行良好).

I'm using Entity Framework 5.0 RC (which worked fine in VS2010 as stated before) with SQL Server 2012 + Tools and IIS express.

推荐答案

我已解决此问题.我改变了这个:

I fixed the problem. I changed this:

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

现在它可以工作了.不过有点愚蠢,我想提供连接字符串作为参数.

And now it works. A bit stupid though, I'd like to supply the connection string as a parameter.

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

I found this out by creating a new MVC 4 project with entity framework in VS 2012, and comparing the Web.Config files. I noticed another difference.

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

My Entity Framework assembly has version 4.4.0.0 (although I installed the 5.0 RC from NuGet). The new project that I created has an assembly with version 5.0.0.0. Can anyone explain that?

这篇关于找不到类型'System.Data.Entity.Infrastructure.SqlConnectionFactory'的构造方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆