经过一些测试,我找到了可能的解决方案。让我们从头开始:
从 sqlite 服务器(x86 版本)下载 SQLite ado.net 提供程序。
您必须在 GAC 中手动注册这三个库:system.data.sqlite、system.data.sqlite.ef6、system.data.sqlite.designer 和 gacutil
启动 Visual Studio 2013。添加对 nuget sqlite 1.0.92.0 的引用(这也将添加对实体框架 6.1 的引用)。
您的 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>
<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>
<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>
<connectionStrings>
在服务器资源管理器中添加到数据库的新 Sqlite 连接并进行测试。
现在向您的项目添加并创建一个新的空 ado.net 实体模型。
这应该可以工作...但是当您运行应用程序并在其中一个 dbset 中获取一些记录时,您将收到一个异常,告诉您没有为您的连接注册 ado.net 提供程序 (system.data.sqlite) .
转到您的配置文件并将其添加到您的提供程序部分(只需复制前面的 sqlite 行并剪切不变名称中的 .ef6 后缀):
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
保存所有并重建应用程序。现在它可以工作了,但是如果您返回模型详细信息并尝试从数据库中刷新模型,您将再次获得提供程序异常。注释最后添加的提供程序并重试。它的工作原理!!!
我认为这是由于 syste.data.sqlite 和 system.data.sqlite.ef6 中的提供程序名称之间存在冲突
尽管如此,我不能先做模型(投影一个模型,然后从中创建一个新数据库),因为我遇到了另一个 ado.net 提供程序异常。
对此有什么想法吗?
谢谢
洛伦佐
_________________ 04-2014 年更新 _________________
经过一些测试和谷歌搜索...
我读到,当你想使用 VS 设计工具时,你必须安装正确的 x86 版本的 SQLite 驱动程序。这些驱动程序要与 VS 工具正常工作,需要在安装过程中在 GAC 中注册其 System.Data.SQLite 版本(只有在此 VS 知道在哪里可以找到设计工具的连接提供程序之后)。
当您使用模型优先的方法并要求模型创建数据库而不是使用在 app.config 中注册的正确驱动程序时,它会尝试打开与在 GAC 中注册并由可视模型创建工具使用的实体连接(并且不兼容)。我认为目前没有办法将 VS 的实体建模工具与 SQLite 提供程序一起使用。
洛伦佐