数据库首先使用system.data.sqlite 1.0.93创建实体框架6.1.1模型

时间:2014-08-01 22:04:11

标签: entity-framework sqlite

我有一个项目,我刚刚使用nuget更新。这个更新的实体框架从6.1到6.1.1,它将sqlite更新为1.0.93。我想从我最新的数据库更新我的模型。我做了几步 1)来自数据库的模型 2)选择sqlite数据库 3)生成

生成后,我收到以下错误消息,如下所示。我安装了1.0.93设计时组件。有谁知道究竟是什么导致了这个错误。项目参考和版本都与上面显示的版本相匹配。

错误讯息:

您的项目引用了最新的实体框架;但是和Entity Framework数据库提供程序 与您的数据连接无法找到与此版本兼容的内容。

更新

我最终使用包管理器控制台手动安装6.1.0

Install-Package EntityFramework -Version 6.1.0

然后在我的csporj文件中替换

包\ EntityFramework.6.1.1

包\ EntityFramework.6.1.0

我尝试从数据库创建EF Designer,从数据库创建Code First但我仍然遇到同样的错误。

更新

我已按照汤姆提供的指示行事,感谢您抽出时间深度回应,感谢您的光临。但我不能让实体框架设计师使用SQLite 1.0.93。我发现了:

1)当我从工具菜单中添加SQLite数据源时,如Tom所述,我看到了SQLite数据提供者。

Tools > Connect to Data Source

2)但是当我重新启动visual studio时,数据源没有连接

After restart connection is lost

3)数据源可以刷新,重启后有效

Tables are shown after refresh

4)添加新数据项但SQLite未列为提供者

SQLite is not listed as a provider

我已经仔细检查了注册表,并且EF6被附加到不变名称,SQLite dll在GAC中注册。我会试着看看还能找到什么但是在这一点上我不知道该找什么。作为旁注,我尝试过dotConnect,它对EF 6.1.1也不起作用。

更新2

有没有人知道Entity Framework Designer是否有一个日志选项来找出可能发生的事情?

6 个答案:

答案 0 :(得分:16)

[更新:为了更简单的解决方案,与Visual Studio 2013 Update 4(Pro和Ultimate)以及最新版本的Sqlite Providers和EF一起使用,请查看解决方案' broslav&#39 ;发布在下面。不知道它是否适用于Express版本......]

好的,这是一个建议。这不适用于Visual Studio Express版本。 此外,我不知道如何让它用于更新现有项目。 这是一个绝对痛苦的屁股。 我还没有测试是否需要一切,但这应该有效:

首先,不要将NuGet包用于SQLite,而是从此处下载程序集安装程序: http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

安装32位Windows(.NET Framework 4.5.1)安装程序的安装程序:sqlite-netFx451-setup-bundle-x86-2013-1.0.93.0.exe(10.00 MiB)(不是64位版本) 。这是设计师唯一的一个。

安装并选择在GAC中安装并安装Designer for VS13。

对于以下内容,确切顺序非常重要!

我制作了有关这些步骤的视频,请参阅:http://vimeo.com/103372740

在VS13中创建项目。将构建目标明确定位到框架4.5.1和x86。保存并构建。

接下来,从NuGet安装最新的EF 6软件包(6.1.1)。保存并构建。

手动添加对已安装的SQLite程序集(包括Designer)的引用,在Assemblies下的Reference Manager下,您可以找到Extensions选项,用于在GAC中选择四个添加的程序集:System.Data.SQLite Core + Designer + for Entity Framework + for LINQ ..保存和构建。

然后通过“工具”下的“连接到数据库”创建与数据库的连接。在您执行任何其他操作之前保存并生成,然后 RESTART Visual Studio。在启动ADO.NET实体数据模型向导之前,请不要执行任何操作,因此请勿刷新数据库连接。

添加ADO.NET实体数据模型,选择“从数据库生成”。 您的数据库连接将显示在下拉列表中。保持不变,但无论如何选择创建一个新连接并再次选择完全相同的数据库(就好像您正在创建一个新连接)。听起来很傻,但这很重要,请看下面的图片......

Connect Entity Model

当我实际上以这种方式添加ADO.NET实体数据模型时,它确实呈现了令人讨厌的错误,但是Next按钮是可选择的并且一切正常无论如何(令人惊讶)!

Designer工作,检索数据和编写数据。

Haven未在另一台计算机上测试过部署......我使用的是Win7 64位。

更改更新:要获得正确配置以实际访问数据库,您必须在执行所有之后从NuGet安装System.Data.SQLite.EF6程序包以上,然后添加 <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> 到App.Config并删除其他提供程序并删除<system.data></system.data>之间的所有内容,否则您将获得一些异常。但请注意,这意味着每次要更新EDMX模型时,都必须更改App.Config invariantName =&#34; System.Data.SQLite&#34; to invariantName =&#34; System.Data.SQLite.EF6&#34;反之亦然。

**这变得荒谬了吗?是的!它让我很头疼...... **

答案 1 :(得分:11)

这对我有用:

所以我的包裹是:

    <packages>
      <package id="EntityFramework" version="6.1.1" targetFramework="net451" />
      <package id="System.Data.SQLite" version="1.0.94.1" targetFramework="net451" />
      <package id="System.Data.SQLite.Core" version="1.0.94.0" targetFramework="net451" />
      <package id="System.Data.SQLite.EF6" version="1.0.94.0" targetFramework="net451" />
      <package id="System.Data.SQLite.Linq" version="1.0.94.1" targetFramework="net451" />
    </packages>

和适用于我的app.config有内容:

<?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>
  <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" />
    </providers>
  </entityFramework>
  <system.diagnostics>
    <sources>
      <!-- This section defines the logging configuration for My.Application.Log -->
      <source name="DefaultSource" switchName="DefaultSwitch">
        <listeners>
          <add name="FileLog" />
          <!-- Uncomment the below section to write to the Application Event Log -->
          <!--<add name="EventLog"/>-->
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="DefaultSwitch" value="Information" />
    </switches>
    <sharedListeners>
      <add name="FileLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" initializeData="FileLogWriter" />
      <!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
      <!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
    </sharedListeners>
  </system.diagnostics>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
  <system.data>
    <!--
        NOTE: The extra "remove" element below is to prevent the design-time
              support components within EF6 from selecting the legacy ADO.NET
              provider for SQLite (i.e. the one without any EF6 support).  It
              appears to only consider the first ADO.NET provider in the list
              within the resulting "app.config" or "web.config" file.
    -->
    <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>
  <connectionStrings>
    <add name="WorkinDataEntities" connectionString="metadata=res://*/WorkinDataModel.csdl|res://*/WorkinDataModel.ssdl|res://*/WorkinDataModel.msl;provider=System.Data.SQLite.EF6;provider connection string=&quot;data source=X:\dev\proj\workin\bin\data.db&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

正如您所看到的,最终,对我来说,没有必要从invariantName中删除“EF6”或删除或重新排列其他提供程序或默认连接工厂。我没有做任何reg hacks。在启动项目的app.config中重新排列add / remove标签(在NuGet System.Data.SQLite 1.0.94.1软件包安装期间添加)是有所不同的。

完成上述所有操作后,我通过NuGet将EntityFramework更新为6.1.2,并通过设计器从数据库更新模型,并在运行时访问数据仍然有效。

答案 2 :(得分:3)

我终于有步骤将Sqlite和EF6一直添加到项目中:

EF6:版本6.0.0为6.1.3(目前是最新版本)。 System.Data.Sqlite:1.0.93 - 1.0.95但不是1.0.98(目前是最新版本)。

为避免获取System.Data.Sqlite 1.0.98,请不要使用Nuget Package Manager进行安装。手动安装System.Data.Sqlite。不幸的是,http://system.data.sqlite.org/并不容易列出以前的下载。

x86 System.Data.Sqlite 1.093

x64 System.Data.Sqlite 1.093

我使用Nuget Package Manager并安装EF6然后我手动添加了System.Data.Sqlite库。我已多次尝试使用1.0.98,但我不能

App.config File

对于我的实现,我首先使用数据库手动编码实体数据类

 public partial class MyDbContextEF : DbContext
{
    public MyDbContext() : base("name=MyDbContext") { }

    public DbSet<DataRecord> DataRecords { get; set; }
}

[Table("TableName")]
public class DataRecord
{
    [Key]
    public Int64 RowID { get; set; }
    public string Name { get; set; }
}

答案 3 :(得分:2)

我报告了此问题并且正在进行修复,并且似乎可以使用解决方法(我尚未对其进行测试)http://system.data.sqlite.org/index.html/tktview?name=e634e330a6

答案 4 :(得分:2)

我遇到了完全相同的问题 - 模型设计师向导没有在下拉列表中显示我的sqlite数据库。我能够通过摆弄sqlite数据库连接和表来解决它。

0a)我通过Server Explorer添加了一个连接到我的sqlite文件(sqlite提供者和服务器在服务器资源管理器的新连接向导中显示,但不是我的edmx模型向导) 0b)此时它仍未显示在edmx模型向导中,但在服务器资源管理器中显示为数据连接。 1)我在sqlite文件中添加了一个表。 2)我通过Server Explorer关闭了与sqlite db的连接 3)我通过服务器资源管理器打开了我的虚拟表的设计和sqlite文件(从而重新启动连接) 4)我试图“从数据库更新模型......”,它显示在下拉列表中

我上面没有包含的另一个步骤是创建并删除了.mdf SQL服务器数据库New Item... > Database Service...。我在尝试上述步骤之前不久就这样做了。我认为这无所谓,但你永远不会知道。

不知道到底是做了什么。它似乎是手动断开并通过服务器资源管理器重新连接使VS“唤醒”并在列表中显示服务器。尝试摆弄连接和表格,看看是否会唤醒一些东西。

答案 5 :(得分:1)

我也有这个问题。原因可能是我在安装system.data.sqlite驱动程序时忘记勾选visual studio复选框,然后安装了该复选框并勾选复选框,而不首先卸载system.data.sqlite驱动程序。这就是我解决它的方法:

  1. 卸载system.data.sqlite驱动程序。
  2. 重新启动。
  3. 安装system.data.sqlite驱动程序
  4. 删除旧解决方案并重新设置,就像您一样(可能没有必要)。
  5. 添加ADO.NET实体模型(模板遗失给我,this answer helped with that
  6. 现在应该可以使用sqlite数据源。