使用实体框架6和SQLite的问题 [英] Problems using Entity Framework 6 and SQLite

查看:100
本文介绍了使用实体框架6和SQLite的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用SQLite使用Entity Framework。我将问题整合到我的主要应用程序中,所以我从头开始进行一些测试,完全按照 http://brice-lambson.blogspot.com/2012/10/entity-framework-on-sqlite.html

I'm trying to use Entity Framework with SQLite. I had issues integrating it into my main application, so I started a little test from scratch, exactly following the directions on http://brice-lambson.blogspot.com/2012/10/entity-framework-on-sqlite.html

执行完毕后,我收到以下错误:

After all is said and done, I get the following error when running the project:


没有找到实体框架提供者具有
不变名称System.Data.SQLite的ADO.NET提供程序。确保提供程序是
注册在应用程序config
文件的entityFramework部分。请参阅 http://go.microsoft.com/fwlink/?LinkId=260882&hl=zh_CN 更多
信息。

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

我的app.config如下所示:

My app.config looks like this:

<?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安装他更新的提供商。错误已经消失了,但是用这个代替:

Then I saw his post about Entity Framework 6. While it wasn't the exact error I was getting, I tried installing his updated provider via NuGet. The error was gone, but replaced with this one:


无法加载文件或程序集System.Data.SQLite.Linq,
Version = 2.0.88.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139'或
其依赖关系之一。找到的程序集的清单定义
与程序集引用不匹配。 (来自HRESULT的异常:
0x80131040)

Could not load file or assembly 'System.Data.SQLite.Linq, Version=2.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

此外,我的app.config已更改(略)为: p>

Additionally, my app.config got changed (slightly) to this:

<?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包,等等。

I've tried everything I can think of to address these errors, nothing has worked. I've tried using the other SQLite binaries; I've tried manually editing the SQLite project to use the EF version 6; I've changed the architectures, I've added and removed the nuget packages over and over, etc.

我不知道从这里去哪里。 >

I have no idea where to go from here.

推荐答案

基于magicandre1981的评论,我开始更仔细地查看提供者节点的语法。我发现我的程序集是与type属性中指定的不同的版本,尽管我没有插入或触摸该特定行。通过删除强大的命名,我得到.Net加载库。作为参考,这里是新行:

Based on magicandre1981's comment, I began to look more closely at the syntax of the provider node. I found that my assembly was a different version than what was specified in the type attribute, though I had not inserted or touched that particular line. By deleting the strong naming, I got .Net to load the library. For reference, here's the new line:

<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq" />

让我回到正轨,我能够将我的结果与博客上的结果相匹配。

That put me back on track and I was able to match my results with the ones on the blog.

然而,我不得不注意到,我已经决定,SQLite不适合实体框架,因为缺少太多的关键功能。我切换到我通过NuGet安装的SQL Server Compact Edition。简单的调整我的连接字符串和我正在运行与实体框架的全部力量。与SQLite的多小时的聊天时间相比,花了不到一分钟的时间。如果可能,我建议切换数据库,System.Data.SQLite尚未准备好实体框架。

I feel compelled to note, however, that I have decided that SQLite is not a good fit for the Entity Framework, as too many critical functions are missing. I switched over to SQL Server Compact Edition, which I installed via NuGet. A simple tweak to my Connection String and I was running with the full power of Entity Framework. It took less than a minute, compared to the multi-hour slog that was SQLite. I'd recommend switching databases if possible, System.Data.SQLite just isn't ready for the Entity Framework.

这篇关于使用实体框架6和SQLite的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆