The error Unable to determine the provider name...
can indicate the .csproj
for the Core project is not set correctly per the instructions on Get Started with ASP.NET Core and Entity Framework 6.
In my case I was working with Core 2.2 project and trying to leverage Entity Framework 6 from .Net Framework 4.7.1 class library, but failed to change the Core .csproj
file from <TargetFramework>netcoreapp2.2</TargetFramework>
to <TargetFramework>net471</TargetFramework>
.
When I finally made the target framework change, the next error to appear was Microsoft.AspNetCore.All 2.2.1 is not compatible with net471 (.NETFramework,Version=v4.7.1)
. I removed the NuGet Microsoft.AspNetCore.All
package, which then created a lot of missing reference build errors.
To resolve the build errors I had to google the missing type to find the assembly name, add that specific NuGet package, rebuild, then keep repeating the process until all of my build errors were resolved.
Every project is different, but here were the packages I had to add to fix my build issues after removing Microsoft.AspNetCore.All
:
<PackageReference Include="EntityFramework" Version="6.2.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
After build issues were resolved and the project built successfully, my DotNet Core 2.2 API was able to return data using Entity Framework 6 from the class library project.
To summarize, the System.NotSupportedException
occurred because the generated Entity Framework classes (in the .NET Framework 471 class library) were being accessed by the DotNet Core version of Entity Framework and not the .NET Framework 4.7.1 version of Entity Framework.
Before making the changes listed above, evaluating System.Data.Common.DbProviderFactories.GetFactoryClasses().Rows
in the Immediate debug window showed an empty collection of providers. After making the changes, the Factory Classes included the Odbc, OleDb, Oracle, SqlServer providers.
More specifically if you evaluate the rows individually, you should see the providers are from the Full .NET Framework.
For example: System.Data.Common.DbProviderFactories.GetFactoryClasses().Rows[3].ItemArray
(for me) showed it came from "System.Data.SqlClient.SqlClientFactory, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”
.