I am developing ASP.NET Core Web API for an ASP.NET MVC project. So, all services are written based on MVC and I should only call them, however, I come across the above error. I have tried the below codes, unfortunately, none of them worked.
I used RegisterFactory in the Configure method of the Startup class to add the invariantName:
DbProviderFactories.RegisterFactory("System.Data.SqlClient", System.Data.SqlClient.SqlClientFactory.Instance);
I then added the provider to appsetting.json:
"entityFramework": {
"providers": {
"provider": {
"invariantName": "System.Data.SqlClient",
"type": "System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"
}
}
}
Some additional information:
- The .NET Core version is 2.2
- The EF version is 6.0.0
- The
Microsoft.EntityFrameworkCore.Toolsversion is 3.1.20