Entity Framework 6.0 in MVC 5 project not working

asp.net-mvc c# entity-framework entity-framework-6

Question

My current setup:

VS1013-Solution

  • MvcProject (MVC5)
  • FrameworkProject (ClassLibrary) - BaseController, BaseViewModel, ets.
  • EntitiesProject (ClassLibrary) - The edmx only as .cs file
  • EntitiesProjectIO (ClassLibrary) - InBetweenLayer to fetch get/set data in the underlying database

I added references to 'EntitiesProjectIO' to my 'MvcProject' and made a call to 'GetData(...)'.

Schema specified is not valid. Errors: \r\nSurgeryManagementEntities.ssdl(2,2) : error 0152: 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. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

is the message I get and I have now idea what the *** is going on. I already added references to nearly every known assembly, copied files from the DB-only project (EntitiesProject). Also copied EntityFramework.dll, tried NuGet for the prjects referencing the DB-Library... Edited the web.config, App.config, whatever.config. Still the same error

Update:

It's a brand new project/solution created within VS2013. Therefore I have no upgrade-issues or something else. Just a clean new solution...

1
3
3/29/2015 5:33:02 PM

Accepted Answer

Your frontend config file must have the provider registered like this:

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

The app config should have been modified after you added Entity Framework 6 thru nuget (which should have also added references to assembly EntityFramework.dll and EntityFramework.SqlServer.dll), you do that by issuing an "Install-Package EntityFramework -Version 6.0.0" in the Package Manager Console. (notice there are newer versions, see https://www.nuget.org/packages/EntityFramework).

After that, you just need to rebuild the solution (so the app config gets copied to the output folder of the project, where the EDMX designer will look for it).

Your project also needs to target .NET 4 or .NET 4.5 to use EF6.

3
2/27/2015 10:10:32 PM


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