【问题标题】:'No Entity Framework provider found' for EF 6 and SQLite 1.0.96.0EF 6 和 SQLite 1.0.96.0 的“未找到实体框架提供程序”
【发布时间】:2015-05-21 16:39:27
【问题描述】:

我意识到关于这个主题已经有几个类似的问题,但其中许多来自旧版本的 SQLite,据我所知,它不完全支持 EF 6。我从这些线程中尝试了无数建议,要么做错了,要么必须改变。

我正在使用 VS 2013,目标是 .NET 4.5.1,并安装了来自 system.data.sqlite.org download page 的 sqlite-netFx451-setup-bundle-x86-2013-1.0.96.0.exe 包以及 System.Data来自 NuGet 管理器(安装 EF6)的 .SQLite EF6 包。

下面是我当前的 App.config 文件(除了我尝试将版本、文化和公钥变量添加到类型之外,它几乎没有被改动):

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"
      />
    </DbProviderFactories>
  </system.data>
</configuration>

还有我的 packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.2" targetFramework="net451" />
  <package id="System.Data.SQLite.EF6" version="1.0.96.0" targetFramework="net451" />
</packages>

如果我执行诸如尝试从模型生成数据库之类的操作,我会看到以下错误:

没有为 ADO.NET 提供程序找到实体框架提供程序 不变名称“System.Data.SQLite.EF6”。确保提供程序已在“entityFramework”部分注册...

我尝试弄乱 App.config 文件并按照旧线程的建议添加其他提供程序和提供程序,但无济于事。

我该如何解决这个问题?非常感谢任何帮助!

编辑:我设法让它工作得很好,可以使用数据库优先的方法。这是我的 App.config 文件的相关部分:

<providers>
     <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>

<DbProviderFactories>
     <remove invariant="System.Data.SQLite" />
     <remove invariant="System.Data.SQLite.EF6" />
     <add name="SQLite Data Provider (Entity Framework 6)" invariant="System.Data.SQLite.EF6" description=".NET Framework Data Provider for SQLite (Entity Framework 6)" type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
     <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>

我正在使用 EF 6.1.2 和 System.Data.SQLite 1.0.96.0。

【问题讨论】:

  • 我必须添加System.Data.SQLite

标签: c# entity-framework sqlite entity-framework-6


【解决方案1】:

试试这些调整:

<providers>
  ...
  <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
</providers>

<system.data>
    <DbProviderFactories>
        <remove invariant="System.Data.SQLite.EF6" />
        <add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
</system.data>

Entity Framework 6 + SQLite

【讨论】:

  • 我仍然看到同样的错误。澄清一下,我应该在 部分中留下 SQLite 的另一个条目,对吗?所以有一个用于 System.Data.SQLite.EF6 和 System.Data.SQLite。无论哪种方式,它都不起作用。我能够像以前一样查看/创建数据连接,但执行失败。
  • 我的问题是在更新后出现的,所以我更改了我的配置,如链接所示。你的连接字符串是什么样的?
  • metadata=res://*/DbModel.csdl|res://*/DbModel.ssdl|res://*/DbModel.msl;provider=System.Data.SQLite.EF6;提供者连接字符串="数据源=C:\sqlite_test\testDb"
  • 我的提供者只是 System.Data.SQLite;不确定这是否重要。
  • 如果我从 中删除 System.Data.SQLite 不变量,SQLite 将不再显示为“生成数据库向导”数据源窗口中的数据源。我对这个有点不知所措。
【解决方案2】:

搜索了一个星期后,我相信这个问题是 sqlite 团队正在开发的一个特性。

更多信息可以在这里找到 SQLite connection not appearing in Entity Data Model Wizard

编辑: 也许研究一些不同的供应商似乎是值得的。 虽然我自己没有对此进行测试,但http://www.devart.com/dotconnect/ 提供了一些有希望的替代方案并说明了 EF 兼容性。

【讨论】:

  • 感谢您的回复。我最终确实让它运行良好(没有一些 VS 设计工具)来做我需要的事情,但希望在未来的版本中更容易设置。
  • 请问你是怎么解决你的问题的,也许它可以帮助我解决我的问题:)
  • 老实说,那是几周前的事了,而且有很多摆弄。我决定使用数据库优先方法,因为它是一个相对简单的应用程序,并且确实有效。我将发布我的 App.config 属性作为上面的编辑。希望这会有所帮助!祝你好运!
【解决方案3】:

我终于搞定了

我正在使用: 英孚 6.1.3 http://www.microsoft.com/en-us/download/details.aspx?id=40762 和 System.Data.SQLite 1.0.96.0 sqlite-netFx451-setup-bundle-x86-2013-1.0.96.0.exe

我遵循了以下描述: Database first create entity framework 6.1.1 model using system.data.sqlite 1.0.93 (在此描述中安装了实体框架的 nuget 包 - 我也这样做了)

对于 app.config 文件,我使用了以下修复: https://stackoverflow.com/a/24324212/885349 (由tomexou撰写)

最后 SQLite 连接器没有显示在 ADO.Net 实体数据模型映射器中

缺少的链接是 \bin 文件夹。 我必须为以下 dll 设置 "Copy Local" = true 设置:

  • SQLite.Designer
  • System.Data.SQLite
  • System.Data.SQLite.EF6
  • System.Data.SQLite.Linq

仅出于完整性考虑 - 通过 Nuget 以及在 \bin 文件夹中添加

  • 实体框架
  • EntityFramework.SqlServer

并且显示了 SQLite 连接...

【讨论】:

    【解决方案4】:

    我解决了同样的错误,只需在 App.config 中添加一行

    <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
    

    PS:将provider添加到&lt;configuration&gt; > &lt;entityFramework&gt; > &lt;providers&gt;

    【讨论】:

    【解决方案5】:

    这是一个有效的 app.config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
      </startup>
    
      <entityFramework>
        <providers>
          <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
        </providers>
      </entityFramework>
    
      <connectionStrings>
        <!-- use AppDomain.SetData to set the DataDirectory -->
        <add name="MapDbConnectionStr" connectionString="Data Source=|DataDirectory|MapDb.sqlite" providerName="System.Data.SQLite" />
      </connectionStrings>
    
      <system.data>
        <DbProviderFactories>
          <remove invariant="System.Data.SQLite.EF6" />
          <add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
        </DbProviderFactories>
      </system.data>
    
    
    
    </configuration>
    

    【讨论】:

    • 不知道为什么这么难找。英雄。
    • 在不同的解决方案上浪费了这么多时间之后,这是唯一对我有用的东西!
    【解决方案6】:
    public class EFConfiguration : DbConfiguration
    {
        public EFConfiguration()
        {
            SetDefaultConnectionFactory(new LocalDbConnectionFactory("v.11"));
    
            //HACK
            var EF6ProviderServicesType = typeof(System.Data.SQLite.EF6.SQLiteProviderFactory).Assembly.DefinedTypes.First(x => x.Name == "SQLiteProviderServices");
            var EF6ProviderServices = (DbProviderServices)Activator.CreateInstance(EF6ProviderServicesType);
            SetProviderServices("System.Data.SQLite.EF6", EF6ProviderServices);
            SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
            SetProviderFactory("System.Data.SQLite.EF6", System.Data.SQLite.EF6.SQLiteProviderFactory.Instance);
            SetProviderFactory("System.Data.SQLite", System.Data.SQLite.SQLiteFactory.Instance);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      • 2014-07-28
      • 2013-12-05
      • 1970-01-01
      • 2015-02-23
      相关资源
      最近更新 更多