Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
922 views
in Technique[技术] by (71.8m points)

.net core - Error Could not load type System.Data.OleDb.OleDbConnection from assembly System.Data when using Scaffold-DbContext, EntityFrameworkCore.Jet, .NetCore

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

I get the following error:

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

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>

I'm using the EntityFrameworkCore.Jet provider.

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

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

Scaffold SQL database works fine.

Already went to https://github.com/bubibubi/EntityFrameworkCore.Jet/wiki/Limitations

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The following types were not available to .NET Core (outside of Preview) until September 2019:

  • System.Data.OleDb.OleDbCommand
  • System.Data.OleDb.OleDbCommandBuilder
  • System.Data.OleDb.OleDbConnection
  • System.Data.OleDb.OleDbDataAdapter
  • System.Data.OleDb.OleDbDataReader
  • System.Data.OleDb.OleDbParameter
  • System.Data.OleDb.OleDbParameterCollection
  • System.Data.OleDb.OleDbTransaction

They are now available in the System.Data.OleDb Nuget package which targets .NET Core 2.1, .NET Framework 4.6.1, .NETStandard 2.0 and other frameworks.

If you add this package you should now be able to target .NET Core or, if you prefer, multi-target both .NET Core and the .NET Framework.

See also: The GitHub issue which led to the development and release of this package.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...