System.Data.SQLite 1.0.91.0及EF6.0.2 [英] System.Data.SQLite 1.0.91.0 and EF6.0.2

查看:227
本文介绍了System.Data.SQLite 1.0.91.0及EF6.0.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人得到了新的System.Data.SQLite 1.0.91.0与实体框架6工作在Visual Studio 201#?如果你有,你是怎么做到的呢?

Has anyone gotten the new System.Data.SQLite 1.0.91.0 to work with Entity Framework 6 in Visual Studio 201#? If you have, how did you do it?

更新 - 二零一四年三月二十零日:System.Data.SQLite 1.0.92.0已被释放,但我没有运气在VS2013创建一个EDMX :(我结束了使用软件包管理器(因为EF6 ##是在依赖使用。新的SQLite的NuGet包):

Update - 20 Mar 2014: System.Data.SQLite 1.0.92.0 has been released but I had no luck creating an EDMX in VS2013 :( I ended up using using Package Manager (because EF6.#.# is a dependency in the new SQLite NuGet package):

uninstall-package entityframework -force

重启VS2013,并把旧EF5上获得VS2013从现有的数据库中生成一个EDMX:

restart VS2013 and put the older EF5 on to get VS2013 to generate an EDMX from an existing database:

install-package entityframework -version 5.0.0

请注意:这不是一个复杂的,多表的SQLite关系型数据库的测试,所以我不知道会出现什么其他的问题,如果我不使用任何东西超过几导航(FK)关系:/

Note: This was not a complex, multi-table SQLite relational database test so I am not sure what other problems will arise if I do use anything with more than a couple Navigation (FK) relationships :/

解答EDMX /型号第一:(更新 - 2014年3月2日),我发现了一个解决方法,但它是不够一致,需要太多的步骤,认为这是一个有效的解决方案。基本上是:

ANSWER for EDMX/Model First: (Update - 2 Mar 2014) I found a work-around but it is not consistent enough and requires too many steps to consider it a valid solution. Basically:


  • 你让所有的类(ES)文件(S),

  • you make all the Class(es) file(s),

请与表的现有SQLite数据库的连接,

make a connection to an existing SQLite database with tables,

修改web / app.config中通过在依然突出SQLite的故障单mistachkin描述(<一个href=\"http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77\">http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77),包括伪造的CDSL / .ssdl / .msl件,以及

modify the web/app.config to as described by mistachkin in the still outstanding SQLite Trouble Ticket (http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77), including faking the cdsl/.ssdl/.msl pieces, and

然后重建项目之前手动创建所有在一个空的EDMX设计器中的实体模型,然后...

then manually create all the Entity Models in the Designer in an Empty EDMX before rebuilding the project and then...

您在实体上单击右键,选择更新从数据库'...

your right click on an Entity and choose 'Update from database'...

有时EF / VS2013将添加.TT / DbContesxt,有时他们没有。路太'漫无':(

Sometimes EF/VS2013 will add the .tt/DbContesxt and sometimes they don't. Way too 'hit or miss' :(

为code首先使用和不使用现有的SQLite数据库ANSWER(基于PMCB,Drexter和吉米的建议)。但是请注意,你不能产生任何EF模型或EDMX文件[原文如此 - 概念模式定义语言(.CSDL),存储架构定义语言(.SSDL)和映射规范语言(.MSL)在Visual Studio 2013年我做了自动不尝试手动创建EDMX文件,看他们是否有可口EF,即使我做到了,在我看来,这样做的所有手动创建/映射/修改/ XML编辑击败一个基于实体框架的整体目标/理念...

ANSWER for "Code First" with and without an existing SQLite database (based on PMCB, Drexter, and Jimi's suggestions). Note however that you cannot generate any EF models or EDMX files [sic - Conceptual Schema Definition Language (.CSDL), Store Schema Definition Language (.SSDL), and Mapping Specification Language (.MSL)] automatically in Visual Studio 2013. I did not try manually creating the EDMX files to see if they would be palatable to EF and even if I did, it seems to me that doing all the manual creation/mapping/changes/XML edits defeats the whole purpose/concept of a entity based framework...

<connectionStrings>
    <add name="DogsContext" connectionString="Data Source=|DataDirectory|\dogs.s3db;" providerName="System.Data.SQLite" />
</connectionStrings>
<entityFramework>
    <providers>
       <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </providers>
</entityFramework>
<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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
</system.data>

下面是测试类(请注意,我不得不将DogID改变的Int64得到它与SQLite的工作... ...):

Here is the test Class (note that I had to change the DogID to Int64 to get it to work with SQLite...):

using System.Data.Entity;

namespace WebApplication1.Models
{
    public class Dog
    {
        public Dog() { }

        public Int64 DogID { get; set; }
        public string DogName { get; set; }
    }
}

和这里是测试的DbContext:

and here is the test DbContext:

using System.Data.Entity;

namespace WebApplication1.Models
{
    public class DogsContext : DbContext
    {
        public DogsContext() : base() { }

        public DbSet<Dog> DogNames { get; set; }
    }
}

=============问题的原有细节==================

============= Original Details of Question ==================

SQLite的1.0.91.0发布昨日(<一个href=\"http://system.data.sqlite.org/index.html/doc/trunk/www/news.wiki\">http://system.data.sqlite.org/index.html/doc/trunk/www/news.wiki)与添加实体框架6支持有一个在包括自述已添加以下以下内容的web.config /的app.config一个警告:

SQLite 1.0.91.0 was released yesterday (http://system.data.sqlite.org/index.html/doc/trunk/www/news.wiki) with "Add support for Entity Framework 6". There is a caveat in the included 'Readme' that has you add the following to the following to web.config/app.config:

<configuration>
<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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
</system.data>
</configuration>

如果您使用的NuGet在VS2013中增加System.Data.SQLite(在x86 / x64),你现在得到这个行加入到web.config中/的app.config:

If you use NuGet in VS2013 to add "System.Data.SQLite (x86/x64)", you now get this line added to web.config/app.config:

<entityFramework>
...
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
...
</entityFramework>

作为测试,我做了一个工作NET4.5.1 / MVC4 / EF5 / System.Data.SQlite 1.0.90应用程序的副本,跑PM:更新包就可以了。它成功添加上述行来我的web.config和我添加了必需的DbProviderFactories作品。重新生成并运行......与无商发现'失败。我尝试没有DbProviderFactories......与无商发现'失败。我删除了新的提供者一片......与无商发现'失败。所以我尝试一种新的项目,但有和没有身份(OWIN)的情况下,这就是问题所在。无论是工作... pretty多江郎才尽,所以在这里问谷歌后/计算器搜索。

As a test, I made a copy of a working NET4.5.1/MVC4/EF5/System.Data.SQlite 1.0.90 application and ran PM: update-package on it. It successfully added the above line to my web.config and I added the required "DbProviderFactories" pieces. Rebuild and run... Fail with 'no provider found'. I try it without the "DbProviderFactories"... Fail with 'no provider found'. I remove the new "provider" piece... Fail with 'no provider found'. So I try a new project but with and without Identity (OWIN) in case that is the problem. Neither work... Pretty much run out of ideas, so asking here after Google/StackOverflow searches.

============ 2014年2月14日===============

============ 14 Feb 2014 ===============

不幸的是,更改的条目和许多变化并没有在我的电脑上工作...
我使用Win8.1专业版64位VS 2013专业版。
我重新安装了System.Data.SQLite。
至少我得到同时与现有的SQLite数据库和VS2013创建新的(我可以访问和查看它与零表的结构合理),新的错误:

Unfortunately the changed entries and numerous variations did not work on my PC... I am using VS 2013 Pro on Win8.1 Pro x64. I reinstalled System.Data.SQLite. At least I am getting a new error with both the existing SQLite database and the new one that VS2013 created (which I can access and see it has a proper structure with zero tables):

"An error occurred connecting to the database. The database might be unavailable. An 
exception of type 'System.Data.Entity.Core.ProviderIncompatibleException' occurred. The 
error message is: Schema specified is not valid. Errors: StoreSchemaDefinition(2,64) : 
Error 0175: The ADO.NET provider with invariant name 'System.Data.SQLite.EF6' is either 
not registered in the machine or application config file, or could not be loaded. See the 
inner exception for details.'"

这两个EF6并在通过的NuGet拉到进入全新的MVC Web应用程序和一个Windows控制台应用程序System.Data.SQLite(86/64)。这两个公司生产的上述错误......我开始怀疑,或许真的是错了我的VS3013,但我不想再花6小时下载和修补它,当我可以MVC4 / SQLite的/ EF5工作...

Both EF6 and System.Data.SQLite (x86/x64) where pulled in via NuGet into brand new MVC Web apps and a Windows Console app. Both produced the above error... I am beginning to suspect that maybe something is wrong with my VS3013 but I do not want to spend another 6 hours downloading and patching it when I can work with MVC4/SQLite/EF5...

===== 2014年2月17日========

===== 17 Feb 2014 ========

@Jimi - 这里没有运气。我试着用NET 4.5和4.5.1用新的MVC和Windows应用程序项目。我试着用EF6.​​0.0和EF6.0.2。我试图从的NuGet加入System.Data.SQLite(在x86 / x64)之后,从安装System.Data.SQLite与本地副本替换3倍SQLite.Data.xxx.dll裁判。我也试过的NuGetSystem.Data.SQLite.MSIL包,而不是添加到DBFactories,我试图Web.Config中和App.Config中的各种版本。

@Jimi - No luck here. I tried with NET 4.5 and 4.5.1 with a new MVC and Windows Application Project. I tried with EF6.0.0 and EF6.0.2. I tried replacing the 3x SQLite.Data.xxx.dll refs with local copies from the install of System.Data.SQLite after adding "System.Data.SQLite (x86/x64)" from NuGet . I also tried the NuGet "System.Data.SQLite.MSIL" package instead of adding DBFactories to the various versions of Web.Config and App.Config that I tried.

我也尝试创建一个.NET 4.0 MVC4 Web应用程序,但它出现的NuGet的System.Data.SQLite(在x86 / x64)现在包括了EF6的要求。作为有希望,我就跟着去了与它尝试各种保存/新建连接/编辑web.config中的/ etc',但它是行不通的。我放弃了现在回去与数据集SQLite的,所以我可以通过使数据表AsEnumerable使用Linq与System.Data.DataSetExtensions(或Java(JDBC)对于那些希望在自己的Andr​​oid数据库的脱机副本的人用最少的应用程序接口的操作系统的设备)。

I also tried creating an NET 4.0 MVC4 Web Application but it appears NuGet’s "System.Data.SQLite (x86/x64)" now includes a requirement for EF6. Being hopeful, I went along with it and tried the various ‘save/create new connection/edit web.config/etc’ but it would not work. I have given up for now and gone back to SQLite with Datasets so I can use Linq with System.Data.DataSetExtensions by making the DataTables "AsEnumerable" (or Java (jdbc) for people that want an offline copy of the database on their Android OS devices with a minimal App interface).

========= 2014年2月19日=======

========= 19 Feb 2014 =======

@Christian萨澳 - 我没有得到EF6和System.Data.SQLite(或System.Data.SQLite.EF6)一起工作,但......但

@Christian Sauer - I did not get EF6 and System.Data.SQLite (or System.Data.SQLite.EF6) to work together, yet... but

我刚刚找到一个更新的<一个href=\"http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77\">http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77即说,有一个新的SQLite的NuGet包:

I just found an update on http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77 that says there is a newer SQLite NuGet package:

mistachkin added on 2014-02-19 03:39:35:

All NuGet packages have been updated to 1.0.91.3.  Several fixes are included
that pertain to supporting Entity Framework 6.

我现在有一个新的项目(MVC Web项目在VS2013使用EF6.​​0.2和SQLite 1.0.91.3的面向.NET 4.5.1)测试它...

I am testing it now with a new Project (MVC Web Project in VS2013 using EF6.0.2 and SQLite 1.0.91.3 that targets .NET 4.5.1)...

新的SQLite 1.0.91.3再次没有运气。在web.config中已更改为:

No luck again with the new SQLite 1.0.91.3. The web.config has changed to:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <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" />
      <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" />
   </DbProviderFactories>
 </system.data>

我要尝试的工作(由吉米和PCMB建议)之后,配置搞乱和发布任何调查结果。

I am going to try messing with the config after work (as suggested by Jimi and PCMB) and post any findings.

我只是试图重新安装都32,然后将64位System.Data.SQLite版本(具有和不具有添加到GAC)但EF6不会与SQLite的工作。如果我尝试手动建立模型和映射,它没有我参考/任何时候尝试使用EF6。作为创建实体数据模型(无论是从现有的SQLite的或新的SQLite数据库生成),它将会失败/错误了,无论我做什么,以CONFIGS,连接或供应商。

I just tried re-installing both the 32 and then the 64 bit versions of System.Data.SQLite (with and without adding to GAC) but EF6 will not work with SQLite. If I try to manually build the model and mappings, it fails any time I reference/try to use EF6. As for creating Entity Data Models (be it generate from existing SQLite or new SQLite database) it will fail/error out no matter what I do to configs, connections or providers.

=========== 2014年2月22日=============

=========== 22 Feb 2014 =============

他们把/回滚的System.Data.SQLite 1.0.91.3更新1.0.91.0。还有一个优秀的票(<一个href=\"http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77\">http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77)打开包括由mistachkin一些建议,这是在app.config mistachkin建议尝试(这个配置并没有为我之前或工作...):

They pulled/rolled-back the System.Data.SQLite 1.0.91.3 update to 1.0.91.0. There is still an outstanding ticket (http://system.data.sqlite.org/index.html/tktview?name=7b8fd3ef77) open that includes some suggestions by mistachkin. Here is the app.config mistachkin recommended trying (this config did not work for me either before or...):

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>
  <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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
     <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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="northwindEFEntities" connectionString="metadata=res://*/NorthwindModel.EF6.2013.csdl|res://*/NorthwindModel.EF6.2013.ssdl|res://*/NorthwindModel.EF6.2013.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=.\northwindEF.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <entityFramework>
    <providers>
     <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </providers>
  </entityFramework>
</configuration>

我试过mistachkin的建议,我们添加DLL到GAC后(使用.NET的Gacutil.exe一起做)...

after I tried mistachkin's suggestion to add the dll's to the GAC (done with .NET "gacutil.exe")...

推荐答案

我今天的工作在这几个小时计算出来了。该的NuGet包添加适当的条目System.Data.SQLite.EF6进入的EntityFramework供应商的工厂,但是你必须删除或注释掉旧的System.Data.SQLite条目。 EF英孚背景建设者炸毁如果任何供应商的条目是无效的,和旧的1.0.91 SQLite的提供者未在EF6支持。

I worked on this for several hours today before figuring it out. The NuGet package adds the appropriate entry "System.Data.SQLite.EF6" into the EntityFramework provider factories, but you have to remove or comment out the old "System.Data.SQLite" entry. The EF context builder blows up if any of the provider entries are invalid, and the old 1.0.91 SQLite provider is not supported in EF6.

编辑:清理的配置让我的其他上下文对象(SQL Server)的实例,但它仍然不会实例SQLite的情况下正确的对象。该内部异常是

Cleaning up the config allowed my other context objects (SQL Server) to instantiate, but it still won't instantiate the SQLite context objects correctly. The inner exception is

找不到请求的.NET Framework数据提供程序。它可能不
  被安装。

Unable to find the requested .Net Framework Data Provider. It may not be installed.

编辑2 / SOLUTION
终于找到它了!我觉得有一个在System.Data.SQLite一个问题,迫使到System.Data.SQLite提供者的名称,而不是在连接字符串中提供的值的参考。我能够通过在的EntityFramework提供部分创建两个条目来解决这个问题,一个名为System.Data.SQlite,一个名为System.Data.SQLite.EF6,但两者提供商实际使用EF6人员。

EDIT 2/SOLUTION Finally figured it out! I think there's an issue in System.Data.SQLite that is forcing a reference to the System.Data.SQLite provider name rather than the value provided in the connection string. I was able to work around this by creating two entries in the EntityFramework provider section, one named "System.Data.SQlite", and one named "System.Data.SQLite.EF6", but both providers actually use the EF6 provider.

<entityFramework>
...
<providers>
    <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>

这篇关于System.Data.SQLite 1.0.91.0及EF6.0.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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