如何解决警告:元素“entityFramework”具有无效的子元素“提供者”。可能的元素列表:'上下文' [英] How to resolve Warning : The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'

查看:723
本文介绍了如何解决警告:元素“entityFramework”具有无效的子元素“提供者”。可能的元素列表:'上下文'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩EF不同的工作流程。昨天我做了一个新项目,实体框架6 Nuget 的第一个建议,所以我决定试试,也是一个非常小的项目,完全用于学习,所以我想这将是一个很好的经验,尝试 EF 6 ,因为我主要工作在$ code > Ef 5 。



我的应用程序基于 Code First 方法。解决方案的结构显示在打印屏幕中:





项目 CodeFirstClasses 旨在保留我的Entites。为了简单起见,因为我遵循教程,我只会使用一个类,你可能会看到 - Customer.cs 。我有:

  public class RewardContext:DbContext 
{
//指定基数作为奖励
public RewardContext():base(Rewards)
{
}

//为每个数据项创建一个数据库集
public DbSet<购买>购买{get;组; }
public DbSet< Customer>客户{get;组; }

}

其他类 - 购买客户这是微不足道的,所以我不会将其粘贴到这里。



另一个可以看到的项目是 Windows Forms 项目,只有一个窗体和按钮。在单击事件的按钮我有所有的逻辑添加新的记录到我的两个实体硬编码。这里只是其中的一部分:

  //某些代码... 
//添加记录并保存它
context.Customers.Add(newCustomer);
context.Purchases.Add(newPurchase);
context.SaveChanges();

MessageBox.Show(Record added!);

到目前为止,与以前的 EF 5 。我可以构建项目,我可以运行它,一切按预期执行。然而,我从标题中得到这个警告:



警告1元素entityFramework有无效的子元素'提供者'。可能的元素列表:'contexts'。即使我主要使用 MS SQL Server Management Studio 我注意到我'我无法从IDE中管理我的连接/数据库 - Visual Studio 2012 ,但这不是一个问题,而$ code> EF 5 。



我的研究缩小了可能的问题/解决方案来手动更改 App.config 文件,但这是一个我没有多少经验的领域,特别是当IDE处理它直到 EF 6 。所以我将为这个解决方案发布我的 App.config 文件:



CodeFirstClasses 项目:

 <?xml version =1.0encoding =utf -8\" >?; 
< configuration>
< configSections>
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> ;
< / configSections>
< entityFramework>
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework/>
< providers>
< provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< / providers>
< / entityFramework>
< / configuration>

从我的 TestCodeFirst 项目: p>

 <?xml version =1.0encoding =utf-8?> 
< configuration>
< configSections>
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> ;
< / configSections>
< startup>
< supportedRuntime version =v4.0sku =。NETFramework,Version = v4.5/>
< / startup>
< entityFramework>
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework/>
< providers>
< provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< / providers>
< / entityFramework>
< / configuration>

我发现另一个可能的解决方案是:更新xsd for验证EF config部分在web / app.config文件中以识别新添加的EF6元素,我也不知道如何做到这一点。



即使当我打开 MS SQL Server Management Studio 时,我看到为此应用程序创建的数据库,记录被保存,一般似乎工作,但我想要解决这个警告,并了解如何根据 EF 6 正确设置我的应用程序。

解决方案

您可以从此处为VS2012安装EF6 Designer ,它将更新验证配置文件的模式。


I'm playing around with EF different workflows. Yesterday I made a new project and Entity Framework 6 was the first suggestion from Nuget so I decided to give it a try, also it is a very small project entirely for learning purposes so I guess it will be good experience to try EF 6 since I've been working mostly with Ef 5.

My Application is based on Code First approach. The structure of the solution is shown in the print screen:

The project CodeFirstClasses is meant to hold my Entites. For simplicity purposes and because I follow a tutorial I use only one class as you may see - Customer.cs. There I have :

public class RewardContext : DbContext
    { 
        //Specify the name of the base as Rewards
        public RewardContext() : base("Rewards")
        { 
        }

        //Create a database set for each data item
        public DbSet<Purchase> Purchases { get; set; }
        public DbSet<Customer> Customers { get; set; }

    }

And the other classes - Purchase and Customer which are trivial, so I won't paste them here.

The other project as you can see is Windows Forms project with just one form and button on it. On the click event of the button I have all the logic for adding new records to my two entities hardcoded. Here is just a part of it:

    //some code...
    //Add the record and save it
    context.Customers.Add(newCustomer);
    context.Purchases.Add(newPurchase);
    context.SaveChanges();

    MessageBox.Show("Record Added!");

So far nothing different from what I'm used to with EF 5. I can build the project, I can run it, and everything is executed as expected. However I get this warning from the title :

Warning 1 The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'. And even though I'm using mostly MS SQL Server Management Studio I've noticed that I'm not able to manage my connections/databases from the IDE - Visual Studio 2012, but this was not an issue with EF 5.

My research narrowed down the possible source of problem/solution to manually changing the App.config file, but this is an area where I haven't got much experience especially when the IDE took care of it until EF 6. So I'll post both my App.config files for this solution :

The one from the CodeFirstClasses project :

<?xml version="1.0" encoding="utf-8"?>
<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>
  <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>

And from my TestCodeFirst project:

<?xml version="1.0" encoding="utf-8"?>
<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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <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>

And the other possible solution that I found is : updating the xsd for "validating" EF config section in web/app.config file to recognize newly added EF6 elements which I'm also not aware of how exactly to do it.

Even though when I open the MS SQL Server Management Studio I see the database created for this application, the records are saved and generally it seems to work but yet I would like to resolve this warning and get to know how to set up my applications based on EF 6 right.

解决方案

You can install the EF6 Designer for VS2012 from here and it will update the schema that validates config files.

这篇关于如何解决警告:元素“entityFramework”具有无效的子元素“提供者”。可能的元素列表:'上下文'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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