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>
-
stackoverflow.com/questions/18455747, stackoverflow.com/questions/21175713, stackoverflow.com/questions/21641435Robert Harvey– Robert Harvey04/16/2014 15:59:43Commented Apr 16, 2014 at 15:59
-
robsneuron.blogspot.com/2013/11/…Robert Harvey– Robert Harvey04/16/2014 16:00:25Commented Apr 16, 2014 at 16:00
2 Answers 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.
-
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– Paritosh04/16/2014 16:06:32Commented Apr 16, 2014 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– Martin Costello04/16/2014 16:11:58Commented Apr 16, 2014 at 16:11
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.
Explore related questions
See similar questions with these tags.