我有一个与MVC应用程序一起使用的存储库库。它可以很好地工作,没有任何问题。
目前,我正在使用.Net Core构建一个新的客户端应用程序。我引用了我的现有存储库项目,该项目具有目标框架4.6.1。我可以顺利构建。
在尝试使用现有的DB上下文访问数据时,我收到了一个错误,指出找不到DefaultConnection字符串。
public class MyAppContext : DbContext
{
public MyAppContext():base("name=DefaultConnection"){}
这是我在config.json中的连接。
"ConnectionStrings": {
"DefaultConnection": "Data Source=[SERVER]; Initial Catalog=[CATALOG]; User ID=[USERID];
Password=[PASSWORD];MultipleActiveResultSets=true;" },
我在我的.Net Core应用程序中添加了一个app.config文件,就像下面这个例子一样:
<?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>
现在我遇到了下面的错误
消息 “在应用程序配置文件中为具有不变名称 'System.Data.SqlClient' 的 ADO.NET 提供程序注册的实体框架提供程序类型'System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer' 无法加载。确保使用程序集限定名并且该程序集可供正在运行的应用程序使用。有关更多信息,请参见http://go.microsoft.com/fwlink/?LinkId=260882。” 字符串
我试图将 .net EntityFramework 安装到我的 .net core 应用程序中,但收到了一个警告,说它不能完全兼容,而且我得到了相同的错误,只是版本较短。
如何使 .Net Core Web 应用程序共享 .Net 4.6 库,而不必重写这些库以使用 .Net Core?