实体框架6 + SQLite [英] Entity Framework 6 + SQLite
问题描述
我正在尝试使用EF6 alpha和SQLite 1.0.66.0
I'm trying to use EF6 alpha and SQLite 1.0.66.0
我的.config文件:
My .config file:
<connectionStrings>
<add connectionString="data source=:memory:;" name="TestDbContext" providerName="System.Data.SQLite" />
</connectionStrings>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<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.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</DbProviderFactories>
</system.data>
当我运行
using (var dbContext = new TestDbContext())
{
if (dbContext.Database.Exists())
{
dbContext.Database.Delete();
}
dbContext.Database.Create();
}
我收到错误:
System.InvalidOperationException:System.InvalidOperationException:
实体框架提供程序的Instance成员类型
'System.Data.SQLite.SQLiteFactory,System.Data .SQLite,
Version = 1.0.66.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139'
没有返回继承自
'System.Data.Entity.Core.Common.DbProviderServices'的对象。实体框架
提供者必须从此类扩展,Instance成员必须
返回提供者的Singleton实例。
System.InvalidOperationException: System.InvalidOperationException: The 'Instance' member of the Entity Framework provider type 'System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must extend from this class and the 'Instance' member must return the Singleton instance of the provider..
我做错了什么?
推荐答案
如果您使用EF 6.1.3 + System.Data.SQLite v1 .0.96.0,只需调整(添加)web.config中的以下声明。 (你可以找到一些文本比较工具的区别,我已经编号了)。
if you used EF 6.1.3 + System.Data.SQLite v1.0.96.0, just adjust(add) the following declarations in the web.config. (you can find the difference with some text-compare tool, i have numbered them).
<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" />
<!-- 1. Solves SQLite error of "Unable to find the requested .Net Framework Data Provider."-->
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</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" />
<!-- 2. Solves SQLite error of "Unable to find the requested .Net Framework Data Provider."-->
<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" />
</DbProviderFactories>
</system.data>
它适用于我。
这篇关于实体框架6 + SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!