EF6找不到LocalDBConnectionFactory [英] EF6 can't find LocalDBConnectionFactory

查看:191
本文介绍了EF6找不到LocalDBConnectionFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个项目:类库(如DAL层)和ASP.NET MVC的项目(如UI)。为了获取数据我尝试使用EF6,但它不工作。
所有异常文本:

I have 2 projects: class library(as DAL layer) and ASP.NET MVC project(as UI). For getting data I try to use EF6, but it doesn't work. All the exception text:

'System.InvalidOperationException'类型的异常出现在EntityFramework.dll但在用户code没有处理

An exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll but was not handled in user code

其他信息:发现与不变名称'System.Data.SqlClient的'ADO.NET提供程序没有实体框架提供。确保供应商注册在应用程序配置文件的EntityFramework部分。

Additional information: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file.

在DAL的app.config我有这样的:

In DAL app.config I have this:

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

EF生成的连接字符串sqex preSS提供商:

EF generates connection string with sqexpress provider:

数据源= \\ SQLEX $ P $干燥综合征;初始目录= DAL.Entity.DataContext;集成安全性= TRUE; MultipleActiveResultSets = TRUE

Data Source=.\SQLEXPRESS;Initial Catalog=DAL.Entity.DataContext;Integrated Security=True;MultipleActiveResultSets=True

P.S。请帮助,我会恨这个该死的东西。

P.S. Please, help, I'm going to hate this damn thing.

推荐答案

为了您的DAL项目有适当的配置设置,您必须在您的web.config中的EntityFramework信息。这样做的原因是用户界面项目是主组件,因此,所有的配置信息必须来自其配置文件。当你编译,引用的程序配置文件不用于配置,只有主配置文件。

In order for your DAL project to have the proper configuration setup, you have to include the EntityFramework information in your web.config. The reason for this is the UI project is the primary assembly and as such, all configuration information must come from its configuration file. When you compile, referenced assembly configuration files are not used for configuration, only the primary configuration file.

随着中说,这里是在最低限度使用的EntityFramework web.configuration文件。确保您在配置文件中正确嵌套的标签。

With that said, here is the bare minimum web.configuration file for using EntityFramework. Ensure that you have the tags nested correctly within the configuration file.

    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <connectionStrings>
        <add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=DAL.Entity.DataContext;Integrated Security=True;MultipleActiveResultSets=True" />
      </connectionStrings>
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
    </configuration>

请注意,我不是说要复制/粘贴,而是看元水平,并确保你有嵌套水平,你的web.config是正确的。其无序的元素将导致500.19配置错误。

Note that I am not saying to copy/paste this, but rather look at the element levels and ensure you have the nesting levels correct in your web.config. Having elements out of order will cause a 500.19 configuration error.

这篇关于EF6找不到LocalDBConnectionFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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