我正在尝试理解SQlite和实体框架之间的交互方式。
我在Visual Studio 2013中创建了一个新的控制台项目。我安装了SQlite 1.0.92的NuGet包。
我创建了一个新的空模型(edmx),并尝试从静态示例数据库(如northwind.db)填充它。
之后,我遇到了这个错误:错误0175:计算机上未注册名为“System.Data.SQLite.EF6”的ADO.NET提供程序。
有什么想法吗?
谢谢
Lorenzo
经过一些测试,我找到了一个可能的解决方案。让我们从头开始:
从 SQLite 服务器下载 SQLite ado.net 提供程序(x86 版本)。您必须使用 gacutil 手动在 GAC 中注册这三个库:system.data.sqlite、system.data.sqlite.ef6 和 system.data.sqlite.designer。
启动 Visual Studio 2013。添加对 NuGet SQLite 1.0.92.0 的引用(这也将添加对 Entity Framework 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>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />