c# - 元素 'entityFramework' 具有无效的子元素 Entity Framework

标签 c# asp.net .net asp.net-mvc entity-framework

我创建新项目 web asp.net mvc 4,当我转到工具 -> 库包管理器 -> 管理包的 nuget 解决方案时。并安装了 Entity Framework 。安装警告列表中显示后是

Warning: The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'.

我正在使用 visual studio 2010,当转到 web.config 时,提供程序标签上有一条下划线

</providers>

由于出现警告,我在寻找解决方案的同时尽力而为

How to resolve Warning : The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'


The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'

但是失败这个错误的原因是什么以及如何处理。
web.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<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>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <modules runAllManagedModulesForAllRequests="true" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <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>
  <connectionStrings> 
  <add name="EmployeeContext"
       connectionString = "server=WALEED-PC\UOG; database=sample; Integrated Security=SSPI"
       providerName="System.Data.SqlClient"/>
  </connectionStrings>


  </configuration>

最佳答案

注意:执行此操作时,您必须关闭 visual studio。完成所有过程后,您必须重新启动 Visual Studio。

我也遇到了同样的问题。我通过复制两个文件来解决这个错误

(1)EntityFrameworkCatalog.xml文件 (2)EntityFrameworkConfig_6_0_0.xsd

来自 https://entityframework.codeplex.com/SourceControl/latest#src/EFTools/setup/EFToolsMsi/XmlSchemas/EntityFrameworkCatalog.xml

并将这些文件放在

C:\Program Files\Microsoft Visual Studio 10.0\Xml\Schemas”文件夹。

首先从上面的链接下载整个 zip 文件。 从下面的位置提取上述两个文件(xml,xsd)

src\EFTools\setup\EFToolsMsi\XmlSchemas

并复制到

C:\Program Files\Microsoft Visual Studio 10.0\Xml\Schemas”。

为什么因为软件每天都在更新。因此我们必须使用更新的软件。

(或)

您可以从“http://www.microsoft.com/en-us/download/details.aspx?id=40762”安装适用于 VS2012 的 EF6 设计器,它将更新验证配置文件的架构。

关于c# - 元素 'entityFramework' 具有无效的子元素 Entity Framework ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20068833/

相关文章:

c# - 如何跨多个服务器在 OWIN 中为 IIS 使用 OAuth AccessTokenFormat?

c# - NHibernate SchemaExport 不创建 ntext 列

c# - 如何使用 Orchard 使用的程序集的新版本

c# - 有没有圆括号?有什么不同?

c# - 调用 `ObjectDisposedException` 时避免 `Invoke`

c# - 从 TypeSyntax 获取 SyntaxTree

c# - Entity Framework 检查 OnModelCreating 期间是否存在列

c# - 如何在mvc中获取网页的特定部分?

jquery - 日历设计

c# - 如何从 DataTable 的最后一行中检索值?