简体   繁体   English

实体框架核心和 MS Access

[英]Entity Framework Core and MS Access

I'm attempting to use an Access database from a WPF MVVM application using JetEntityFrameworkProvider and I can't get it to work.我正在尝试使用JetEntityFrameworkProvider从 WPF MVVM 应用程序使用 Access 数据库,但我无法让它工作。 I've created the models, created the migrations using Add-Migration but when I run Update-Database, the command never finishes.我已经创建了模型,使用 Add-Migration 创建了迁移,但是当我运行 Update-Database 时,该命令永远不会完成。 It does create the database but the only table is MSysAccessStorage.它确实创建了数据库,但唯一的表是 MSysAccessStorage。 There is a section of the documentation that says有一部分文档

In order to make the provider work, the table MSysRelationships should be accessible from Administrator为了使提供者工作,表 MSysRelationships 应该可以从管理员访问

and further says并进一步说

This is the default configuration so no needs to make changes.这是默认配置,因此无需进行更改。 Access since version 2003 has visible system tables so no need to assign rights.自 2003 版以来的访问具有可见的系统表,因此无需分配权限。 The configuration must be done setting the right dual table (very early in your code).必须完成配置,设置正确的双表(在代码的早期)。

JetConnection.DUAL = JetConnection.DUALForAccdb; JetConnection.DUAL = JetConnection.DUALForAccdb;

I've tried adding this but I can't figure out where "very early in your code" is.我试过添加这个,但我无法弄清楚“在你的代码中很早”在哪里。 I've added it to the top of my App.xaml.cs and to my database context and neither worked.我已将它添加到我的 App.xaml.cs 的顶部和我的数据库上下文中,但都不起作用。 When I add it I get:当我添加它时,我得到:

The name 'DUAL' does not exist in the current context.当前上下文中不存在名称“DUAL”。 The name 'JetConnection.DUALForAccdb' does not exist in the current context.当前上下文中不存在名称“JetConnection.DUALForAccdb”。

This is my OnConfiguring in my context这是我在上下文中的 OnConfiguring

protected override void OnConfiguring( DbContextOptionsBuilder optionsBuilder )
{
    optionsBuilder.UseJet( @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\<User>\Desktop\New Folder\Staff.accdb;" );
}

What am I not doing correctly?我做错了什么?

The JetEntityFramework provider is not compatible with EF Core. JetEntityFramework 提供程序与 EF Core 不兼容。

Instead, use EntityFrameworkCore.Jet if you want to use EF Core (same author as JetEntityFramework, not affiliated), or use EF 6 if you want to use JetEntityFramework.相反,如果您想使用 EF Core(与 JetEntityFramework 相同的作者,不附属),请使用EntityFrameworkCore.Jet,如果您想使用 JetEntityFramework,请使用 EF 6。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM