问题描述
我意识到关于这个主题已经有几个类似的问题,但其中许多来自旧版本的 SQLite,据我所知,它并不完全支持 EF 6.我从这些线程中尝试了无数建议,要么做错了,要么必须改变.
I realize there are already several similar questions on this topic, but many of them are from older version of SQLite which did not fully support EF 6 as far as I am aware. I have tried countless suggestions from these threads and am either doing something wrong or something must have changed.
我正在使用 VS 2013,以 .NET 4.5.1 为目标,并已从 system.data.sqlite.org 下载页面,以及来自 NuGet 管理器的 System.Data.SQLite EF6 包(安装 EF6).
I am using VS 2013, targeting .NET 4.5.1 and have installed the sqlite-netFx451-setup-bundle-x86-2013-1.0.96.0.exe package from the system.data.sqlite.org download page, as well as the System.Data.SQLite EF6 package from the NuGet Manager (which installs EF6).
下面是我当前的 App.config 文件(除了我尝试将版本、文化和公钥变量添加到类型之外,它几乎没有被改动):
Below is my current App.config file (it is pretty much untouched except I tried adding the Version, Culture, and Public key variables to the type):
<?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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<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, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</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, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"
/>
</DbProviderFactories>
</system.data>
</configuration>
还有我的 packages.config:
And my packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.2" targetFramework="net451" />
<package id="System.Data.SQLite.EF6" version="1.0.96.0" targetFramework="net451" />
</packages>
如果我执行诸如尝试从模型生成数据库之类的操作,我会看到以下错误:
If I do something such as attempt to Generate a Database from Model I see the following error:
找不到 ADO.NET 提供程序的实体框架提供程序不变名称System.Data.SQLite.EF6".确保提供者已在entityFramework"部分注册...
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6'. Make sure the provider is registered in the 'entityFramework' section...
我尝试弄乱 App.config 文件并按照旧线程的建议添加其他提供程序和提供程序,但无济于事.
I've tried messing around the the App.config file and adding other providers and providers as old threads have suggested but to no avail.
我该如何解决这个问题?非常感谢任何帮助!
How do I fix this problem? Any help is greatly appreciated!
我设法让它工作得很好,可以使用数据库优先的方法.这是我的 App.config 文件的相关部分:
I managed to get it to work well enough to use a database first approach. Here is the relevant parts of my App.config file:
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
<DbProviderFactories>
<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" />
<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>
我使用的是 EF 6.1.2 和 System.Data.SQLite 1.0.96.0.
I'm using EF 6.1.2 and System.Data.SQLite 1.0.96.0.
推荐答案
我解决了同样的错误,只是在 App.config 中添加了一行
I solved same error with just add a single line in App.config
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
PS:将provider
添加到
>
>
PS: Add provider
to <configuration>
> <entityFramework>
> <providers>
这篇关于EF 6 和 SQLite 1.0.96.0 的“未找到实体框架提供程序"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!