【问题标题】:System.Data.SQLite 1.0.91.0 and EF6.0.2System.Data.SQLite 1.0.91.0 和 EF6.0.2
【发布时间】:2014-03-12 13:03:27
【问题描述】:

有没有人获得新的 System.Data.SQLite 1.0.91.0 以在 Visual Studio 201# 中与实体框架 6 一起使用?如果有,你是怎么做到的?

更新 - 2014 年 3 月 20 日:System.Data.SQLite 1.0.92.0 已发布,但我没有运气在 VS2013 中创建 EDMX :( 我最终使用了包管理器(因为 EF6.#.# 是新的 SQLite NuGet 包):

uninstall-package entityframework -force

重启 VS2013 并安装旧版 EF5 以让 VS2013 从现有数据库生成 EDMX:

install-package entityframework -version 5.0.0

注意:这不是一个复杂的多表 SQLite 关系数据库测试,所以我不确定如果我确实使用具有多个导航 (FK) 关系的任何东西会出现什么其他问题:/

EDMX/Model First 的回答:(更新 - 2014 年 3 月 2 日)我找到了一种解决方法,但它不够一致,需要太多步骤才能将其视为有效的解决方案。基本上:

  • 你制作了所有的 Class(es) 文件,

  • 使用表连接到现有 SQLite 数据库,

  • 将 web/app.config 修改为 misachkin 在仍然未完成的 SQLite 故障单 (http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77) 中所描述的内容,包括伪造 cdsl/.ssdl/.msl 片段,以及

    李>
  • 然后在重新构建项目之前,在 Designer 中的 Empty EDMX 中手动创建所有实体模型,然后...

  • 右键单击实体并选择“从数据库更新”...

有时 EF/VS2013 会添加 .tt/DbContesxt,有时不会。太“命中或错过”:(

有和没有现有 SQLite 数据库的“代码优先”的答案(基于 PMCB、Drexter 和 Jimi 的建议)。但是请注意,您无法在 Visual Studio 2013 中自动生成任何 EF 模型或 EDMX 文件 [原文 - 概念架构定义语言 (.CSDL)、存储架构定义语言 (.SSDL) 和映射规范语言 (.MSL)]。我做到了不要尝试手动创建 EDMX 文件以查看它们是否适合 EF,即使我这样做了,在我看来,进行所有手动创建/映射/更改/XML 编辑都会破坏基于实体的框架的整个目的/概念...

<connectionStrings>
    <add name="DogsContext" connectionString="Data Source=|DataDirectory|\dogs.s3db;" providerName="System.Data.SQLite" />
</connectionStrings>
<entityFramework>
    <providers>
       <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </providers>
</entityFramework>
<system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
</system.data>

这是测试类(请注意,我必须将 DogID 更改为 Int64 才能使其与 SQLite 一起使用...):

using System.Data.Entity;

namespace WebApplication1.Models
{
    public class Dog
    {
        public Dog() { }

        public Int64 DogID { get; set; }
        public string DogName { get; set; }
    }
}

这里是测试 DbContext:

using System.Data.Entity;

namespace WebApplication1.Models
{
    public class DogsContext : DbContext
    {
        public DogsContext() : base() { }

        public DbSet<Dog> DogNames { get; set; }
    }
}

=============问题的原始细节===================

SQLite 1.0.91.0 昨天发布 (http://system.data.sqlite.org/index.html/doc/trunk/www/news.wiki),带有“添加对实体框架 6 的支持”。包含的“自述文件”中有一个警告,您需要将以下内容添加到 web.config/app.config 中:

<configuration>
<system.data>
    <DbProviderFactories>
        <remove invariant="System.Data.SQLite" />
        <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite"
             type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
</system.data>
</configuration>

如果您在 VS2013 中使用 NuGet 添加“System.Data.SQLite (x86/x64)”,您现在会将此行添加到 web.config/app.config:

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

作为测试,我复制了一个有效的 NET4.5.1/MVC4/EF5/System.Data.SQlite 1.0.90 应用程序并在其上运行 PM: update-package。它成功地将上述行添加到我的 web.config 中,并且我添加了所需的“DbProviderFactories”部分。重建并运行...失败并显示“未找到提供程序”。我在没有“DbProviderFactories”的情况下尝试它......失败并出现“未找到提供者”。我删除了新的“提供者”部分......失败并显示“未找到提供者”。所以我尝试了一个新项目,但有无身份(OWIN),以防万一出现问题。两者都不起作用......几乎没有想法,所以在 Google/StackOverflow 搜索后在这里询问。

============ 2014 年 2 月 14 日 ================

不幸的是,更改后的条目和许多变体在我的电脑上不起作用... 我在 Win8.1 Pro x64 上使用 VS 2013 Pro。 我重新安装了 System.Data.SQLite。 至少我在现有 SQLite 数据库和 VS2013 创建的新数据库(我可以访问并看到它具有零表的正确结构)都遇到了一个新错误:

"An error occurred connecting to the database. The database might be unavailable. An 
exception of type 'System.Data.Entity.Core.ProviderIncompatibleException' occurred. The 
error message is: Schema specified is not valid. Errors: StoreSchemaDefinition(2,64) : 
Error 0175: The ADO.NET provider with invariant name 'System.Data.SQLite.EF6' is either 
not registered in the machine or application config file, or could not be loaded. See the 
inner exception for details.'"

EF6 和 System.Data.SQLite (x86/x64) 通过 NuGet 引入全新的 MVC Web 应用程序和 Windows 控制台应用程序。两者都产生了上述错误......我开始怀疑我的 VS3013 可能有问题,但是当我可以使用 MVC4/SQLite/EF5 时,我不想再花 6 个小时下载和修补它......

===== 2014 年 2 月 17 日 ========

@Jimi - 运气不好。我尝试使用带有新 MVC 和 Windows 应用程序项目的 NET 4.5 和 4.5.1。我尝试使用 EF6.0.0 和 EF6.0.2。从 NuGet 添加 "System.Data.SQLite (x86/x64)" 后,我尝试用安装 System.Data.SQLite 的本地副本替换 3x SQLite.Data.xxx.dll 引用。我还尝试了 NuGet “System.Data.SQLite.MSIL” 包,而不是将 DBFactories 添加到我尝试过的各种版本的 Web.Config 和 App.Config。

我还尝试创建一个 NET 4.0 MVC4 Web 应用程序,但现在 NuGet 的“System.Data.SQLite (x86/x64)”似乎包含对 EF6 的要求。怀着希望,我同意了它并尝试了各种“保存/创建新连接/编辑 web.config/etc”,但它不起作用。我现在已经放弃并使用 Datasets 回到 SQLite,因此我可以通过将 DataTables 设置为“AsEnumerable”(或 Java (jdbc))来将 Linq 与 System.Data.DataSetExtensions 一起用于想要在 Android 上离线复制数据库的人具有最小 App 界面的操作系统设备)。

========= 2014 年 2 月 19 日 =======

@Christian Sauer - 我没有让 EF6 和 System.Data.SQLite(或 System.Data.SQLite.EF6)一起工作,但是......但是

我刚刚在 http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77 上发现了一个更新,它说有一个更新的 SQLite NuGet 包:

mistachkin added on 2014-02-19 03:39:35:

All NuGet packages have been updated to 1.0.91.3.  Several fixes are included
that pertain to supporting Entity Framework 6.

我现在正在使用一个新项目(VS2013 中的 MVC Web 项目,使用面向 .NET 4.5.1 的 EF6.0.2 和 SQLite 1.0.91.3)对其进行测试...

新的 SQLite 1.0.91.3 又不走运了。 web.config 已更改为:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, 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" />
   </DbProviderFactories>
 </system.data>

我会在下班后尝试弄乱配置(如 Jimi 和 PCMB 的建议)并发布任何发现。

我刚刚尝试重新安装 System.Data.SQLite 的 32 位和 64 位版本(添加和不添加到 GAC),但 EF6 不适用于 SQLite。如果我尝试手动构建模型和映射,任何时候我引用/尝试使用 EF6 都会失败。至于创建实体数据模型(无论是从现有 SQLite 还是新 SQLite 数据库生成),无论我对配置、连接或提供程序做什么,它都会失败/出错。

=========== 2014 年 2 月 22 日 =============

他们将 System.Data.SQLite 1.0.91.3 更新拉/回滚到 1.0.91.0。仍然有一张未解决的票 (http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77) 打开,其中包括 misachkin 的一些建议。这是 app.config misachkin 推荐尝试的(这个配置在我之前或之前对我都不起作用......):

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <system.data>
    <DbProviderFactories>
     <remove invariant="System.Data.SQLite" />
     <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
     <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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.EF6.2013.csdl|res://*/NorthwindModel.EF6.2013.ssdl|res://*/NorthwindModel.EF6.2013.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <providers>
     <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </providers>
  </entityFramework>
</configuration>

在我尝试了 misachkin 将 dll 添加到 GAC 的建议之后(使用 .NET "gacutil.exe" 完成)...

【问题讨论】:

  • 你有进步吗?我也被这个问题困住了......
  • 嘿,你终于明白了吗?请说出你的进展...
  • 'EF6.anything' 还没有运气。对于 CRUD 应用程序,我一直在使用 EF5,对于查询,我要么使用基于 JDBC/ODBC SQL 的 DAL 并带有原始返回,要么构建适合 Linq 和 Razor 视图的对象。
  • 如果这仍然是一个问题,也许我发布的这个答案对你有用(另见视频):stackoverflow.com/questions/25089346/…
  • 22 Feb 解决方案终于对我有用了。竖起大拇指

标签: c# entity-framework sqlite


【解决方案1】:

我今天在这个问题上工作了几个小时才弄明白。 NuGet 包将适当的条目“System.Data.SQLite.EF6”添加到 EntityFramework 提供程序工厂,但您必须删除或注释掉旧的“System.Data.SQLite”条目。如果任何提供程序条目无效,EF 上下文构建器就会崩溃,并且 EF6 不支持旧的 1.0.91 SQLite 提供程序。

编辑:清理配置允许我的其他上下文对象(SQL Server)实例化,但它仍然不会正确实例化 SQLite 上下文对象。内部异常是

找不到请求的 .Net Framework 数据提供程序。它可能不会 安装。

编辑 2/解决方案 终于想通了!我认为 System.Data.SQLite 中存在强制引用 System.Data.SQLite 提供程序名称而不是连接字符串中提供的值的问题。我可以通过在 EntityFramework 提供程序部分创建两个条目来解决此问题,一个名为“System.Data.SQlite”,另一个名为“System.Data.SQLite.EF6”,但两个提供程序实际上都使用 EF6 提供程序。

<entityFramework>
...
<providers>
    <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>

【讨论】:

  • Aye :( 我只是尝试直接从已安装的版本(EF 和 SQLite dll)添加引用,但无济于事。稍后从新/干净的项目中尝试...
  • 新项目也没有成功,所以希望像 Brice Lambson 这样的人能读到这篇文章并试图弄清楚:/
  • 检查我的第二次编辑。我让它在提供程序部分中处理重复的条目。
  • 我也有同样的问题。能否发布完整的 app.config 文件内容?
  • 感谢您的尝试,但没有运气:( 至少我收到一个新错误,引用 System.Data.Entity.Core.ProviderIncombatibleException 现有(工作)数据库和 VS2013 创建的有效新数据库。 .. 重新安装 System.Data.SQLite 并尝试了一堆其他的东西都无济于事。至少 MVC4/SQLite/EF5 仍然有效:/
【解决方案2】:

它在 VS 2010 上使用控制台应用程序并首先编写代码对我有用。无论如何,这里是我的 app.config,它基于 Brice 的 EF6 SQLite 教程 (http://www.bricelam.net/2012/10/entity-framework-on-sqlite.html):

<?xml version="1.0"?>
 <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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
  <parameters>
    <parameter value="v11.0"/>
  </parameters>
</defaultConnectionFactory>
<providers>
  <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
  <remove invariant="System.Data.SQLite" />
  <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</DbProviderFactories>
</system.data>
<connectionStrings>
 <add name="ChinookContext" connectionString="Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite" providerName="System.Data.SQLite"/>
</connectionStrings>
</configuration>

【讨论】:

  • 是的,这就是我为任何需要 SQLite 的新项目所做的事情(在 VS2013 中创建一个 2012 MVC4 Web 应用程序,而不是升级 EF...):(
  • 这个 app.config 对我不起作用。我在这里发布了一个类似的问题:stackoverflow.com/questions/21769255/…。这是使用 SQLite 1.0.91 和代码优先但不起作用的项目:sendspace.com/file/ovdxly
  • @YiannisMpourkelis 我下载了你的代码,发现你的 app.config 中有这一行 应该改成这个
  • @PWRR2207 对于您的回复,我有点困惑。如果您说您要不升级 EF,您要完成什么?不幸的是,我确实有 VS 2013,所以我无法最终确认 EF6 和 SQLite 1.0.91.0 是否有效。我会得到一份副本,让你知道我的发现。
  • @Drexter - 我有 VS2010 Pro 和 VS2013 Pro。如果我在其中创建一个 MVC Web App 版本 4 (MVC4) 项目,我可以将实体框架版本 5 (EF5) 与 SQLite 版本 1.90/.91 一起使用。如果我将 EF 升级到版本 6 或尝试创建任何使用 EF6(MVC/WPF/Win 控制台/等)的东西,我将无法在该项目或 Web 中使用任何版本的 System.Data.SQLite。
【解决方案3】:

经过 6 小时的试错尝试、头撞墙以及我们开发人员为弄清楚事情是如何工作所做的其他事情,我相信我设法让它在 VS 2013 上运行。

按照这些步骤。

  1. 如果您还没有安装System.Data.SQLite,请安装。
  2. 从 NuGet 获取项目中的 System.Data.SQLite(注意它在 app.config 中添加了一些内容)。
  3. 这是重要的部分。保存您的解决方案并退出 VS 2013。
  4. 重新加载解决方案,现在您可以将 ADO.NET 实体数据模型添加到您的项目中。

每次您想要添加模型时,您都必须退出 VS 2013 并且必须使用“新建连接...”创建模型

你说为什么会这样?我说,宇宙以神秘的方式运转。

编辑: 进一步研究它,我发现为了打开与模型的连接,您必须将配置中的提供程序从 &lt;provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /&gt; 更改为 &lt;provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /&gt;DbProviderFactories位于system.data 标记内,而不是。

【讨论】:

【解决方案4】:
<providers>
  <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>

这对我有用,但在运行时可能会出现一些内部错误,这可能会导致 EF 喜欢首先使用 2 个其他表作为代码 __MigrationHistory 和 EdmMetadata 之间的差异。我现在认为它是微不足道的,但如果你真的想利用 CodeFirst,我假设现在必须手动创建这些表。

编辑 -- 仅提供者列表中的条目,我删除了对 SqlServer 的所有引用...

Vs2013 Ultimate 最新 SQLite Nuget。

【讨论】:

    【解决方案5】:

    这是我的整个配置文件。我正在使用 SQLite 1.0.91 运行 EF 6.0.2。我还没有尝试过模型生成器,但是我的上下文对象工作正常,我已经通过上下文测试了插入/更新/删除以及通过 dbcontext 的直接 SQL 命令。诀窍在于 entityFramework/providers 部分。我不得不为 EF6 提供程序复制 SQLite 提供程序条目,但使用旧的和新的不变名称。

        <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
        <section name="electra.common.configuration.electraConfiguration" type="Electra.Common.Configuration.ElectraConfiguration, Electra.Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" allowDefinition="Everywhere" allowExeDefinition="MachineToApplication" restartOnExternalChanges="true" />
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
      </configSections>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
      </startup>
      <connectionStrings>
        <add name="DBContext_Server" 
            connectionString="server=sunset\sql2012;Integrated Security=SSPI;database=Electra;Pooling=true;max pool size=1000;min pool size=5;Connection Lifetime=30;connection timeout=15" 
            providerName="System.Data.SqlClient" />
        <add name="DBContext_ElectraPOS" 
            connectionString="Data Source=D:\Electra\ElectraWeb\PosEngine.Repository\ElectraPOS.db" 
            providerName="System.Data.SQLite.EF6" />
      </connectionStrings>
        <system.data>
            <DbProviderFactories>
                <remove invariant="System.Data.SQLite" />
                <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
                <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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
            </DbProviderFactories>
        </system.data>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
        <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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
            <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
        </providers>
      </entityFramework>
      <electra.common.configuration.electraConfiguration>
        <logging>
          <levels info="true" warning="true" error="true" debug="true" />
        </logging>
      </electra.common.configuration.electraConfiguration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.1.0.0" newVersion="2.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    

    【讨论】:

    • 添加 System.Data.SQLite 和 System.Data.SQLite.EF6 让我的项目开始了:
    • 谢谢!我将您的 entityFramework/providers 部分和 system.data/DbProviderFactories 部分数据复制/粘贴到修复了我的解决方案的本地副本上。
    • “诀窍在于 entityFramework/providers 部分。我必须为 EF6 提供程序复制 SQLite 提供程序条目,但使用新旧不变名称。”谢谢!!!!!!!
    • 真的吗?为什么EF还是这么乱?它应该让事情变得更容易
    【解决方案6】:

    我在安装包的过程中遇到了权限问题,所以我收到了这个错误。 我解决了以管理员身份运行 vs2013。

    所以:

    1. 卸载包
    2. 关闭 vs2013
    3. 以管理员身份再次运行(重要)
    4. 再次安装 nugetpackage

    最后我也在提供者中做广告(根据其他用户的建议):

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

    【讨论】:

    • 不幸的是,我知道这不是管理员权限问题,因为过去几个月我一直在使用自定义的“以管理员身份运行”VS2013 快捷方式来减少 Windows 8 的抱怨,因为我在 Web API 上工作提要,我已经忘记了我安装了多少次 NuGet SQLite(和 EF6):(
    【解决方案7】:

    花了几个小时在互联网上挖掘之后,在这里我提出了一个可行的解决方案

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <configSections>
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <entityFramework>
        <providers>
          <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
        </providers>
      </entityFramework>
      <connectionStrings>
        <add name="NorthwindContext" connectionString="Data Source=Northwind.sl3" providerName="System.Data.SQLite.EF6" />
      </connectionStrings>
      <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" />
        </DbProviderFactories>
      </system.data>
    </configuration>
    

    project

    【讨论】:

      【解决方案8】:

      这是对我有用的解决方案。

      安装 System.Data.SQLite 包并确保 db factory 部分如下所示。

      <DbProviderFactories>
        <remove invariant="System.Data.SQLite" />
        <remove invariant="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" />
        <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" />
      </DbProviderFactories>
      

      【讨论】:

        【解决方案9】:

        这对我有用:

        <entityFramework>
            <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" />
            </providers>
        </entityFramework>
        <system.data>
            <DbProviderFactories>
                <remove invariant="System.Data.SQLite" />
                <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
                <!--<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
                <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" />-->
            </DbProviderFactories>
        </system.data>
        

        使用最新的 nuget 包 (1.0.94.1):https://www.nuget.org/packages/System.Data.SQLite/ 和 SQLite 工具:32 位 Windows (.NET Framework 4.5.1) 的设置,http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

        【讨论】:

          【解决方案10】:

          最后这个解决方案对我有用。 点网框架=4.5.1 实体框架=6.1.1

          下载这个:sqlite-netFx451-setup-bundle-x86-2013-1.0.94.0.exe

          <?xml version="1.0" encoding="utf-8"?>
          
          <configuration>
            <configSections>
              <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
              <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
            </configSections>
            <startup>
              <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
            </startup>
          
            <entityFramework>
              <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
              <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" />
              </providers>
            </entityFramework>
          
            <system.data>
              <!--
                  NOTE: The extra "remove" element below is to prevent the design-time
                        support components within EF6 from selecting the legacy ADO.NET
                        provider for SQLite (i.e. the one without any EF6 support).  It
                        appears to only consider the first ADO.NET provider in the list
                        within the resulting "app.config" or "web.config" file.
              -->
              <DbProviderFactories>
                <remove invariant="System.Data.SQLite" />
                <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".Net Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
          
                <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" />
              </DbProviderFactories>
            </system.data>
            <connectionStrings>
              <add name="VelocityDBEntities" connectionString="metadata=res://*/AppData.Model1.csdl|res://*/AppData.Model1.ssdl|res://*/AppData.Model1.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=F:\VelocityPOS\VelocityDB.sqlite&quot;" providerName="System.Data.EntityClient" />
            </connectionStrings>
          </configuration>
          

          【讨论】:

            【解决方案11】:

            只是想分享一下我遇到同样问题的所有经验

            我尝试使用System.Data.SQLite 1.0.94 和EF6,但在连接数据库时遇到了一些问题。我在 VS 2013.4 工作。在按照 pmbc 的建议安装所有必要的软件包并检查 web.config 之后,我仍然遇到了相同的连接问题和 System.Data.Entity.Core.ProviderIncompatibleException 类型的异常。

            在互联网上进行了一些额外的搜索后,我发现这个 VS2013 插件可以与 SQL Compact 和 SQLite 数据库一起使用,这对我很有帮助:https://visualstudiogallery.msdn.microsoft.com/0e313dfd-be80-4afb-b5e9-6e74d369f7a1

            现在我可以使用现有的 SQLite 数据库/从 VS 创建新数据库/使用现有数据库和所有其他东西创建 EF 模型

            希望对你有帮助

            更新

            请提供更多信息以寻求帮助。这是我生成的 .config 文件部分

            <entityFramework>
              <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
              <providers>
                <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.95.0, Culture=neutral" />
                <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.95.0, Culture=neutral" />
              </providers>
            </entityFramework>
            <system.data>
              <DbProviderFactories>
                <remove invariant="System.Data.SQLite" />
                <remove invariant="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" />
                <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" />
              </DbProviderFactories>
            </system.data>
            

            还要检查您本地安装的 System.Data.SQLite.dll 库的版本号(默认情况下,它安装在 GAC 中)您的 GAC 版本和当前项目中的包版本必须相同。否则当你启动你的应用程序时你会捕获一个异常

            【讨论】:

            • 与接受的答案不同,这对我有用,但我必须从提供程序定义中删除 'Version=1.0.95.0, Culture=neutral"'。
            【解决方案12】:

            我遇到了同样的错误,但原因似乎没有被其他答案所涵盖。所以我想分享我自己的案例。

            在包含 EDMX 的程序集中,一切正常。 在客户端(执行)程序集中,我在运行时总是遇到相同的错误(在 ADO 的应用程序配置文件中注册的实体框架提供程序类型“System.Data.SQLite.EF6.SQLiteProviderServices,System.Data.SQLite.EF6”。 NET 提供程序具有不变的名称 'System.Data.SQLite.EF6' 无法加载。)

            我注意到对于 EDMX 程序集,“本地复制”设置为 true,但在执行程序集时没有。我修好了,没问题。 因此,如果您也遇到此问题并且 GAC 中没有 SQLite 提供程序,如果您已为 SQLite DLL 启用“复制本地”,请检查您的参考资料

            我在检查提供商和其他一些事情之前迷失了很长时间,所以我希望它对其他人有所帮助!

            【讨论】:

            • 谢谢!我养成了在 AutoCAD 编码中关闭 Copy Local 的习惯,并将在其他项目中记住这一点。
            【解决方案13】:

            我刚刚为 System.Data.SQLite.EF6 库(在参考 -> System.Data.SQLite.EF6 -> 属性中)设置了 Copy local = True 并且它可以工作

            【讨论】:

              【解决方案14】:

              通过从 Nuget 包管理器安装最新的 SQLite,我在安装 SQLite 包时遇到错误(在处理需要 edmx over sqlite DB 的项目时)。

              第 1 步:仔细阅读消息。它可以揭示错误消息试图传达的内容。

              例如:

              An error occurred while connecting to the database. The database might be unavailable. An exception of type 'System.InvalidCastException' occurred. 
              
              The error message is: '[A]System.Data.SQLite.SQLiteConnection cannot be cast to [B]System.Data.SQLite.SQLiteConnection. 
              
              Type A originates from 'System.Data.SQLite, Version=1.0.105.1, Culture=neutral, PublicKeyToken=db937bc2d44ff139' in the context 'Default' 
              at location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\System.Data.SQLite\v4.0_1.0.105.1__db937bc2d44ff139\System.Data.SQLite.dll'. 
              
              Type B originates from 'System.Data.SQLite, Version=1.0.106.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' in the context 'LoadNeither' 
              at location 'C:\Users\Ganesh Kamath\AppData\Local\Microsoft\VisualStudio\14.0\ProjectAssemblies\og1mcjvn01\System.Data.SQLite.dll'.'.
              

              读完后我意识到我选择了版本 1.0.106.0 进行升级。

              基本上消息说它知道版本 1.0.105.1 但不知道版本 1.0.106.0

              第 2 步:通过在 Visual Studio 中手动选择 Nuget Package for Solution 选项中的出现来删除导致问题的版本。

              工具 > Nuget 包管理器 > 管理用于解决方案的 Nuget 包...

              第三步:使用Nuget命令行安装系统可以理解的SQLite版本。

              在上面的例子中,版本是 1.0.105.1

              工具 > Nuget 包管理器 > 包管理器控制台

              为此所需的命令如下所示:

              Install-Package System.Data.SQLite -Version 1.0.105.1 
              Install-Package System.Data.SQLite.Core -Version 1.0.105.1 
              Install-Package System.Data.SQLite.EF6 -Version 1.0.105.1
              

              【讨论】:

                猜你喜欢
                • 2015-06-13
                • 1970-01-01
                • 1970-01-01
                • 2013-12-11
                • 1970-01-01
                • 1970-01-01
                • 2019-01-26
                • 1970-01-01
                相关资源
                最近更新 更多