错误 使用 Scaffold-DbContext、EntityFrameworkCore.Jet、.NetCore 时,无法从程序集 System.Data 加载类型 System.Data.OleDb.OleDbConnection [英] Error Could not load type System.Data.OleDb.OleDbConnection from assembly System.Data when using Scaffold-DbContext, EntityFrameworkCore.Jet, .NetCore

查看:25
本文介绍了错误 使用 Scaffold-DbContext、EntityFrameworkCore.Jet、.NetCore 时,无法从程序集 System.Data 加载类型 System.Data.OleDb.OleDbConnection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Entity Framework Core 中的 Scaffold-DbContext 从现有的 MS Access 数据库创建模型.

I am trying to use Scaffold-DbContext from Entity Framework Core to create Models from an existing MS Access Database.

在包管理器控制台中运行命令时:

In Package Manager Console when I run the command:

Scaffold-DbContext "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:FolderDatabase.mdb;" EntityFrameworkCore.Jet

我收到以下错误:

Could not load type 'System.Data.OleDb.OleDbConnection' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=123123123'.

我正在使用具有以下设置的 ClassLibrary 项目:

I'm using a ClassLibrary project with the following setup:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <PlatformTarget>AnyCPU</PlatformTarget>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="EntityFrameworkCore.Jet" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.4" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

我正在使用 EntityFrameworkCore.Jet 提供程序.

I'm using the EntityFrameworkCore.Jet provider.

x32 和 x64 OleDb Dll 都在机器中:

Both x32 and x64 OleDb Dll's are in the machine:

C:Program FilesCommon Filesmicrosoft sharedOFFICE14ACEOLEDB.DLL
C:Program Files (x86)Microsoft Office
ootVFSProgramFilesCommonX86Microsoft SharedOFFICE16ACEOLEDB.DLL

从 Microsoft Access Database Engine 2010 Redistributable 安装的 x64和来自 Office Professional Plus 32 位的 x32

The x64 installed from Microsoft Access Database Engine 2010 Redistributable and the x32 from Office Professional Plus 32-bit

脚手架 SQL 数据库工作正常.

Scaffold SQL database works fine.

已经去了https://github.com/bubibubi/EntityFrameworkCore.Jet/wiki/限制

是否缺少某些东西或此设置应该可以工作?任何帮助将不胜感激.

Is something missing or this setup should work? Any help would be appreciated.

推荐答案

您需要以 .Net Framework 为目标.

You need to target .Net Framework.

实际上 OleDb 没有移植到 .Net Core.https://github.com/dotnet/corefx/issues/23542

Actually OleDb is not ported to .Net Core. https://github.com/dotnet/corefx/issues/23542

您可以尝试使用 .Net Framework 4.6 或 4.7.

You can try with .Net Framework 4.6 or 4.7.

这篇关于错误 使用 Scaffold-DbContext、EntityFrameworkCore.Jet、.NetCore 时,无法从程序集 System.Data 加载类型 System.Data.OleDb.OleDbConnection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆