注册新用户-缺少构造函数消息

时间:2018-07-09 05:21:31

标签: asp.net sql-server entity-framework asp.net-mvc-5

[此问题尚无答案]

这与另一个问题here有关,我一直无法找到解决方案。我只是无法使LocalDb与现有项目一起使用。因此,我决定在SSMS中创建一个空白数据库,并为此更新Web.config文件。

我也尝试使用解决this问题的解决方案,但没有任何效果。

尝试注册新用户时出现以下错误:

  

System.MissingMethodException:类型上的构造方法   'System.Data.Entity.Infrastructure.LocalDbConnectionFactory'不是   找到。

我将Entity Framework版本从6.1.3更新为6.2.0,并且仍然是相同的错误。第一次尝试此操作时,它从App_Data文件夹中清除了现有的MDF数据库文件。一路走来,我遇到了各种数据库权限错误。

我的Web.config:

        <connectionStrings>
            <remove name="LocalSqlServer" />
            <add name="LocalSqlServer" connectionString="Initial Catalog=MyDatabase;Data Source=Development;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
       </connectionStrings>

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>

2 个答案:

答案 0 :(得分:0)

尝试一下。

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

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

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

我已删除

<providers>    
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>

并更改

答案 1 :(得分:0)

通过为我的Web.config的entityframework部分添加一个参数条目,我能够克服此错误,如下所示:

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
    <parameters>
      <parameter value="v11.0" />
    </parameters>
  </defaultConnectionFactory>
  <providers>
    <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
  </providers>
</entityFramework>

这导致我解决了original problem,并且我也提供了答案。