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

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

问题描述

我试图使用实体框架的SQLite。我有它融入我的主要应用程序的问题,所以我开始从头开始一个小的测试,正是继<一个方向href=\"http://brice-lambson.blogspot.com/2012/10/entity-framework-on-sqlite.html\">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:

没有发现与ADO.NET提供实体框架提供
  不变的名称'System.Data.SQLite。确保提供商
  在应用程序配置的的EntityFramework部分注册
  文件。见<一href=\"http://go.microsoft.com/fwlink/?LinkId=260882\">http://go.microsoft.com/fwlink/?LinkId=260882更多
  信息。

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>

然后,我看到了他对实体框架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,
  版本= 2.0.88.0,文化=中性公钥= 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得到了改变(略)这样:

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是不适合的实体框架,因为太多的关键功能缺失。我切换到SQL Server精简版,这是我经过的NuGet安装。一个简单的拧紧,我的连接字符串,我与实体框架的全功率运行。它超过一分钟采取以下,相比于多小时猛击这是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天全站免登陆