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

ef-code-first entity-framework entity-framework-6 visual-studio-2012

Question

I'm experimenting with several EF workflows. I created a new project yesterday, andEntity Framework 6 was the initial advice fromNuget I therefore made the decision to test it, and since it is a very tiny project that is only for educational purposes, I believe that trying it will be beneficial.EF 6 since I've been primarily dealing withEf 5 .

Based on what my application isCode First approach. The print screen displays the solution's structure as follows:

Solution Tree

The endeavorCodeFirstClasses intended to house my Entities. Because I'm following a tutorial, I'm keeping things simple and simply using one class, as you can see -Customer.cs . Here it is:

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; }

    }

The other courses also -Purchase and Customer things I won't paste here because they are unimportant.

The second undertaking is, as you can see,Windows Forms project with simply one button and one form. On theclick when the button happens I have hardcoded all the logic necessary to add new records to my two entities. Here's a sample of it:

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

    MessageBox.Show("Record Added!");

Nothing has changed from what I'm used to thus far.EF 5 . The project can be built and operated by myself, and everything goes according to plan. However, the title gives me the following caution:

Warning 1 The element 'entityFramework' has invalid child element 'providers'. List of possible elements expected: 'contexts'. And despite the fact that I primarilyMS SQL Server Management Studio I've found that the IDE doesn't allow me to control my connections or databases.Visual Studio 2012 nonetheless, this was not a problem withEF 5 .

My investigation limited the potential sources of the issue and potential fixes to manually modifying theApp.config file, but I don't have much experience in this area, especially since the IDE handled it until recently.EF 6 . I'll post both of myApp.config for this solution's files:

it came from theCodeFirstClasses 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>

Also, from myTestCodeFirst 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 here's another option I came across:updating the xsd for "validating" EF config section in web/app.config file to recognize newly added EF6 elements which I also don't know exactly how to do.

yet, when I open theMS SQL Server Management Studio I can see the database that was built for this application, the entries are saved, and everything else appears to be working, but I still want to figure out how to fix this warning and set up my applications based on it.EF 6 right.

1
16
10/22/2013 6:47:44 PM

Accepted Answer

Installing the EF6 Designer for VS2012 will update the schema that verifies configuration files.

32
10/22/2013 10:39:14 PM

Popular Answer

Version 5 of the configuration schema was replaced with Version 6. As stated, a contexts node was added to replace the providers node.

Instead of having all contexts use the same provider, the idea is that you may customize the providers separately. (This is related to the ability to have many contexts reside in a same database. Originally known as multi-tenant, this was later renamed to be clearer)



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow