我正试图使用Entity Framework与SQLite。在将它集成到我的主应用程序时遇到了问题,因此我从头开始进行了一项小测试,完全按照http://brice-lambson.blogspot.com/2012/10/entity-framework-on-sqlite.html上的指示进行。
最终,当运行该项目时,我收到以下错误:
未找到带有不变名称'System.Data.SQLite'的ADO.NET提供程序的Entity Framework提供程序。确保该提供程序已在应用程序配置文件的“entityFramework”部分中注册。有关更多信息,请参见http://go.microsoft.com/fwlink/?LinkId=260882。
我的app.config如下所示:
<?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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<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>
<connectionStrings>
<add name="ChinookContext"
connectionString=
"Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite"
providerName="System.Data.SQLite" />
</connectionStrings>
</configuration>
接着我看到他关于Entity Framework 6的帖子。虽然他提供的更新程序并没有解决我遇到的确切错误,但我还是尝试通过NuGet安装了它。错误消失了,但被这个替代了:
无法加载文件或程序集“System.Data.SQLite.Linq, Version=2.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139”或 其中的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。(异常来自 HRESULT: 0x80131040)
此外,我的app.config文件也有所改变(略微)变成了这个样子:
<?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>
<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" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq, Version=2.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<remove invariant="System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="ChinookContext" connectionString="Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite" providerName="System.Data.SQLite" />
</connectionStrings>
</configuration>
我已尽力解决这些错误,但一切都无济于事。我尝试使用其他SQLite二进制文件;我尝试手动编辑SQLite项目以使用EF版本6;我更改了架构,一遍又一遍地添加和删除NuGet包等等。
我不知道接下来该怎么做。