Reputation: 51
I have a repository library that I use with an MVC application. It works great without any issues.
Currently, I'm building a new Client application using .Net Core. I referenced my existing repository project which has target framework 4.6.1. I can build without any issues.
When I tried to access the data using an existing DB Context. I was getting an error that it couldn't find a DefaultConnection string.
public class MyAppContext : DbContext
{
public MyAppContext():base("name=DefaultConnection"){}
this the connection I have in my config.json
"ConnectionStrings": {
"DefaultConnection": "Data Source=[SERVER]; Initial Catalog=[CATALOG]; User ID=[USERID];
Password=[PASSWORD];MultipleActiveResultSets=true;" },
I added an app.config file to my .Net Core application, like the one below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlClient" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=[SERVER]; Initial Catalog=[CATALOG]; User ID=[USERID];
Password=[PASSWORD];MultipleActiveResultSets=true; " providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
and now I'm getting an error below
Message "The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information." string
I tried to install .net EntityFramework to my .net core application and I got a warning that it won't be fully compatible and I was getting the same error just shorter version.
How can I make .Net Core Web Application to share .Net 4.6 library without rewriting them to use .Net Core?
Upvotes: 3
Views: 1948
Reputation: 205619
The answer is no (currently).
While Entity Framework Core can work with both full NET framework and NET Core (because it supports NET Standard), Entity Framework 6 can work only with full NET framework. See Compare EF Core & EF6.
AFAIK there are some plans to add NET Core (or NET Standard) support to EF6 in the future (not sure when), for now the only option is to port the EF6 code to EF Core. But note that there are fundamental differences and EF Core is still unstable (especially the query translation to SQL) and can seriously hurt the performance in case you are using complex LINQ queries. If you use EF just for CRUD, then probably the port is not so problematic.
Upvotes: 2