【问题标题】:Why did <entityFramework> and <configSections> tags appear in my web.config file?为什么 <entityFramework> 和 <configSections> 标签出现在我的 web.config 文件中?
【发布时间】:2019-03-14 20:04:23
【问题描述】:

为什么这段代码会出现在我的 web.config 文件中?我创建 ADO.NET 实体数据模型时它不存在,那么是什么事件触发了此代码的生成?

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

  <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 nuget 包吗?
  • 是的,当我创建 ADO.NET 实体数据模型时,它会通过 NuGet @Will 自动下载并安装 EntityFramework
  • 那就这样吧。
  • 是的,我刚刚在此处docs.microsoft.com/en-us/ef/ef6/fundamentals/configuring/… 的 Microsoft EntityFramework 指南中读到了这一点,奇怪的是我有另一个项目安装了 EF6,但它没有将这些标签放在 web.config 文件中。这就是我感到困惑的原因。

标签: asp.net asp.net-mvc entity-framework web-config


【解决方案1】:

实体框架包会在多个实例中自动安装。例如,当您使用现成的模板(例如启用了个人身份验证的 ASP.Net MVC 项目)创建项目时。因为在这种情况下,应用程序将与 EF 绑定以处理所有与身份验证相关的数据库交互。 其次,如果您添加一个 Model 类和一个带有脚手架的控制器,以使用 Entity Framework 生成视图(“MVC 5 Controller with views, using Entity Framework”)。在这种情况下,如果实体框架尚未配置,则脚手架机制会完成该工作。结果,我们在项目中的 web.config 和 DLL 引用中看到了所有与 EF 相关的配置。当我们开始在 Visual Studio 中处理这些新项目模板时,这会导致一些混乱。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-08-01
    • 1970-01-01
    • 2011-05-01
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多