我是 Entity Framework 的新手,今天我正在尝试开发一个简单的 C# 脚本,它将使用 Entity Framework Core Jet 来列出本地 MS Access DB 中指定的所有公司。
但是,我在“OnConfiguring”函数中不断收到错误消息:
System.TypeLoadException: 'Method 'get_Info' in type 'EntityFrameworkCore.Jet.Infrastructure.Internal.JetOptionsExtension' from assembly 'EntityFrameworkCore.Jet, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.'
请注意,我正在开发的 C# 控制台应用程序是在 .NET Framework 4.7.2 中开发的。我也尝试过使用 .NET Core 3、.NET Core 2.1 等开发相同的脚本,但所有这些都有相同的结果。
我在下面提供了关于数据库的所有信息和我到目前为止编写的代码。
数据库设计
数据库只包含一个名为“Companies”的表,其中包含以下字段:
- ID(自动编号,主键)
- 公司名称(短文本)
DataContext.cs
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;
using EntityFrameworkCore.Jet;
namespace EntityFrameworkCoreJetTest5 {
public class DataContext : DbContext {
public DbSet<Company> Companies { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
//The issue occurrs here
optionsBuilder.UseJet(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\arand\Desktop\EFTestProject\Data\Data.accdb;");
}
}
public class Company {
public int ID { get; set; }
public string CompanyName { get; set; }
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFrameworkCoreJetTest5 {
class Program {
static void Main(string[] args) {
using (DataContext dbContext = new DataContext()) {
foreach(Company c in dbContext.Companies) {
Console.WriteLine(c.CompanyName);
}
}
Console.ReadKey();
}
}
}
谢谢!
最佳答案
System.TypeLoadException: 'Method 'get_Info' in type 'EntityFrameworkCore.Jet.Infrastructure.Internal.JetOptionsExtension' from assembly 'EntityFrameworkCore.Jet, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.'
版本 2.2.0
中的 EntityFrameworkCore.Jet
提供程序仅与 EF Core 2.2.x 兼容。因此它不适用于 EF Core 3.0.0+。
如果您想将 EntityFrameworkCore.Jet
与 EF Core 3.1 一起使用,请使用我们最新的官方预发布版(截至目前,这是 3.1.0-alpha.3
) 来自 nuget.org , 或使用最新的 daily build来 self 们的 AZDO feed .
它符合 .NET Standard 2.0,因此可以与 .NET Framework 4.6.1+ 和 .NET (Core) 2.0+ 一起使用。
关于c# - EntityFrameworkCore.Jet 在尝试连接到 MS Access DB 时返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64277261/