Reputation: 23
I am trying to use EF6.0 in Class Library Project .Net Framework 4.6.2 (Repository project) where the DBContext live next to the repository and the Entities have been created in different project(.NET framework 4.6.2) using Reverse Code First POCO, The Repository will be called thru another (framework 4.6.2) Manager Project referenced inside ASPNET Core 2.0 SPA Project, where StructureMap used as IoC.
The first thing I faced was the issue of passing the connectionstring to the DBContext inside Repository Project, as I want to Register the services (DBContext,Repository) inside the Repository Project not from the ASPNET Core Startup.cs, the reason to that is to avoid exposing the DBContext to the frontend project, anyway I ended up hard-coding the connection string in Repo Project temporarily, "appreciate if there is another way!"
The main issue that I am facing with this design comes when the request send to collect the list of "Products", it reaches to the Repository Project where the Linq statement use _dbcontext.Product , then error message thrown
NotSupportedException: Unable to determine the provider name for provider factory of type 'System.Data.SqlClient.SqlClientFactory'. Make sure that the ADO.NET provider is installed or registered in the application config.
The Entityframework is registered inside Repository project, but not inside ASPNET Core 2.0 Project as it will show Nuget conflict error when its installed in ASPNET Core 2.0.
also I tried to install "System.Data.SqlClient" from Nuget in ASPNET Core2.0 but the error still throwing.
Any Idea on how to use EF6.0 in .netframework 4.6.2 class library project referenced inside ASPNET Core 2.0 project.
Upvotes: 2
Views: 1606
Reputation: 31
curiously I'm also building an asp .net framework 4.6.2 app, to avoid that issue I installed the deprecated and old version of Microsoft.EntityFrameworkCore (2.2.6) and all other packages for EntityFramework, like Microsoft.EntityFrameworkCore.Tools, Microsoft.EntityFrameworkCore.[Database name].
Upvotes: -1
Reputation: 310
The Microsoft article Get Started with ASP.NET Core and Entity Framework 6 has the steps necessary for using Entity Framework 6 from a ASP.NET Core project.
Regarding the NotSupportedException
, I would refer to the related question System.NotSupportedException: Unable to determine the provider name for provider factory of type 'System.Data.SqlClient.SqlClientFactory'.
I ran into the same issue because I failed to change the Core .csproj
file from <TargetFramework>netcoreapp2.2</TargetFramework>
to <TargetFramework>net471</TargetFramework>
(which the article told me to do, but for some reason I thought wasn't necessary in Core 2.2).
I provided more explanation and details in the posted explanation/answer to the question I referenced above.
Upvotes: 0