0

I have the following MVC project structure:

BLL

DAL

CommonClasses

Web

i'm using Entity Framework 6.0.2. The web project has a reference to the BLL and CommonClasses project. BLL has a reference to DAL and CommonClasses. Both BLL and DAL also have references to EF 6.0.2, added via Nuget. Anytime my code tries to do anything with Entity Framework I get the error below:

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file.

I'm a bit lost on what's happening. I have checked and there is a reference to EntityFramework.SqlServer in the DAL and BLL projects. All projects also have a reference to System.Data.

The app.config file in both the DAL and BLL proejcts has the below line:

  <entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
  <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>

Paritosh
  • 4,243
  • 7
  • 47
  • 80

2 Answers2

2

Ensure that EntityFramework.SqlServer.dll is in the application directory for Web1 (i.e. in the bin folder). It doesn't always get copied if the top-level executable/site doesn't have a direct dependency on this file.

Martin Costello
  • 9,672
  • 5
  • 60
  • 72
  • Is there anyway to add in via Visual Studio to it's always there for anyone else who grabs the project? I just manually copied it into the bin and it worked, but how to do it through VS? If I try to add a reference to it in the project, i don't see EntityFramework.SqlServer in the search results. – Paritosh Apr 16 '14 at 16:06
  • The hackiest (TM) way to do it is doing something like this and add a reference into the project using EntityFramework, then it'll get included as a dependency in any downstream projects: internal static readonly Type SqlProviderServicesType = typeof(System.Data.Entity.SqlServer.SqlProviderServices); – Martin Costello Apr 16 '14 at 16:11
1

Please see my SO answer here, which references a blog that was very helpful. I had to do a couple of steps to get that DLL copied and loaded.

Error: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'

Community
  • 1
  • 1
bcr
  • 1,983
  • 27
  • 30