【问题标题】:Entity Framework with Microsoft Access带有 Microsoft Access 的实体框架
【发布时间】:2013-08-25 15:09:45
【问题描述】:

我使用 .accdb 文件。我创建了类

using System.Data.Entity;

    class MSADbContext:DbContext
    {
        public DbSet<Product> Products { get; set; }
    }

并添加连接字符串

<add name="MSADbContext" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\SportsStore.accdb" providerName="System.Data.OleDb"/>

在第一次查询 DB 后,我得到 ProviderIncompatibleException: "calling "get_ProviderFactory" in repository typeOf "System.Data.OleDb.OleDbConnection" 返回 null"

【问题讨论】:

    标签: entity-framework ms-access connection-string


    【解决方案1】:

    您的连接字符串将用于 .mdb (Access 2003-) 文件。检查连接strings here

    您需要 ACE OLEDB 提供程序。标准安全:

    Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;
    Persist Security Info=False;
    

    但是,请先阅读this thread

    Entity Framework 不支持 OLEDB 连接,因此您的 连接字符串将不起作用。几乎不可能得到 与 MS Access 协作的实体框架。

    几乎不可能非常引人注目。

    【讨论】:

      【解决方案2】:

      OLEDB 不能支持实体框架,因为实体框架需要实体框架提供者为特定数据库生成正确的查询(而 OLEDB 是通用数据库访问)。您需要特定的 Microsoft Access 提供程序。

      您可以在此处找到 Microsoft Access 实体框架提供程序 https://jetentityframeworkprovider.codeplex.com/

      编辑
      Access EF 提供程序现在托管在 GitHub 上
      https://github.com/bubibubi/JetEntityFrameworkProvider

      【讨论】:

      • 鉴于CodePlex will be shutting down 的公告,您会将您的项目转移到 GitHub 吗?
      • 我没看到。我会把它移到github上。谢谢!
      猜你喜欢
      • 2015-12-26
      • 2011-08-08
      • 2014-03-24
      • 2018-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多