I used NuGet to install Entity Framework for a new project. To my surprise Entity Framework 6 was installed and version 5 is no longer available. The configuration file is certainly more complicated than it was in version 5. You are now required to have the entityFramework section in the application configuration file even if you are working with code-first.
So I was seeing the following error when running a test that inserted an entity into my database:
I went to the link in the error message and verified the configuration file was properly written during the NuGet package installation. I also saw that a reference had been added to EntityFramework.SqlServer.dll. I opened the assembly in Object Browser and verified that System.Data.Entity.SqlServer.SqlProviderServices was indeed present.
The stack trace was pretty deep, but it started in my DbContext derived class’s constructor:
I figured I try load the type myself so I put in this code in my DbContext derived class’s static constructor:
// Without this line, EF6 will break. var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
My configuration file is shown below for reference. Note than with Entity Framework 5, I only needed the connection string section when working with code-first.
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections> <connectionStrings> <add name="MyDatabase" connectionString="Data Source =.;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings> <entityFramework> <providers> <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /> </providers> </entityFramework> </configuration>