如何解决警告:元素“entityFramework"具有无效的子元素“提供者".预期的可能元素列表:“上下文" [英] How to resolve Warning : The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'
问题描述
我在玩 EF 不同的工作流程.昨天我做了一个新项目,Entity Framework 6
是 Nuget
的第一个建议,所以我决定试一试,它也是一个非常小的项目,完全用于学习目的所以我想尝试 EF 6
会是很好的体验,因为我主要使用 Ef 5
.
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
.
我的应用程序基于 Code First
方法.解决方案的结构显示在打印屏幕中:
My Application is based on Code First
approach. The structure of the solution is shown in the print screen:
CodeFirstClasses
项目旨在容纳我的实体.为简单起见,并且因为我遵循教程,所以我只使用你可能看到的一个类 - Customer.cs
.我有:
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; }
}
还有其他类 - Purchase
和 Customer
是微不足道的,所以我不会在这里粘贴它们.
And the other classes - Purchase
and Customer
which are trivial, so I won't paste them here.
您可以看到的另一个项目是 Windows Forms
项目,上面只有一个表单和按钮.在按钮的 click
事件中,我拥有将新记录添加到硬编码的两个实体的所有逻辑.这里只是其中的一部分:
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!");
到目前为止,与我使用 EF 5
的习惯没有什么不同.我可以构建项目,我可以运行它,并且一切都按预期执行.但是我从标题中得到了这个警告:
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 :
警告 1 元素 'entityFramework' 具有无效的子元素 'providers'.预期的可能元素列表:'contexts'.
尽管我主要使用 MS SQL Server Management Studio
我注意到我无法管理我的连接/数据库来自 IDE - Visual Studio 2012
,但这不是 EF 5
的问题.
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
.
我的研究将问题/解决方案的可能来源缩小到手动更改 App.config
文件,但这是我没有太多经验的领域,尤其是在 IDE 处理时直到 EF 6
.所以我会为这个解决方案发布我的两个 App.config
文件:
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 :
CodeFirstClasses
项目中的那个:
<?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>
从我的 TestCodeFirst
项目中:
<?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>
我发现的另一个可能的解决方案是:更新 xsd 以在 web/app.config 文件中验证"EF 配置部分以识别新添加的 EF6 元素
我也不知道具体怎么做.
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.
即使当我打开 MS SQL Server Management Studio
时,我看到为该应用程序创建的数据库,记录已保存并且通常它似乎可以工作,但我想解决此警告并了解如何基于 EF 6
设置我的应用程序吧.
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屋!