EF 6和SQLite的“未找到实体框架提供程序”1.0.96.0

ttp71kqs  于 2023-05-18  发布在  SQLite
关注(0)|答案(7)|浏览(190)

我意识到已经有几个类似的问题关于这个主题,但其中许多是来自旧版本的SQLite,据我所知,它并不完全支持EF 6。我已经尝试了无数的建议,从这些线程,要么是做错了什么,或一定有什么改变。
我使用的是VS 2013,目标是.NET 451,并且已经从system.data.sqlite.org download page安装了sqlite-netFx451-setup-bundle-x86-2013-1.0.96.0.exe包,以及从NuGet Manager(安装EF 6)安装了System.Data.SQLite EF 6包。
下面是我当前的App.config文件(除了我尝试将Version、Culture和Public key变量添加到类型中之外,它几乎没有动过):

<?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>

如果我做一些事情,例如尝试从模型生成数据库,我会看到以下错误:
找不到具有不变名称“System.Data.SQLite.EF6”的ADO.NET提供程序的实体框架提供程序。确保提供程序已在“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>

我使用的是EF6.1.2和System.Data.SQLite 1.0.96.0。

cdmah0mi

cdmah0mi1#

我只是在App.config中添加了一行代码就解决了同样的错误

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

PS:将provider添加到<configuration>> <entityFramework>> <providers>

yc0p9oo0

yc0p9oo02#

下面是一个可用的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>
dfddblmv

dfddblmv3#

我终于得到了它太工作
我正在使用:EF 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实体数据模型Map器中
缺少的链接是\bin文件夹。我必须为以下dll设置“Copy Local”= true设置:

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

仅用于完整性-通过Nuget添加,也可以在\bin文件夹中添加

  • EntityFramework
  • EntityFramework.SqlServer

SQLite连接显示...

mcvgt66p

mcvgt66p4#

试试这些调整:

<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

ljsrvy3e

ljsrvy3e5#

经过一个星期的搜索,我相信这个问题是sqlite团队在开发中的一个功能。
更多信息可在此处找到SQLite connection not appearing in Entity Data Model Wizard
编辑:也许寻找一些不同的供应商似乎是值得的。虽然我自己没有测试过,但http://www.devart.com/dotconnect/提供了一些有希望的替代方案,并声明了EF兼容性。

at0kjp5o

at0kjp5o6#

没有一个建议的解决方案对我有效。当我试图运行Add-Migration SampleMigrationUpdate-Database时,这里的和答案linked related thread中的都不是。
如果这可能会帮助其他人有同样的问题,我想分享我们目前的解决方案。我不太了解EF,但是一个同事发现了这个解决方法,使VS识别类型并将其包含在构建管道中。

// this is required for migrations to work, VS complains about missing sql providers
var x = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
9w11ddsr

9w11ddsr7#

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);
    }
}

相关问题