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

Entity framework 数据库首先使用system.data.sqlite 1.0.93创建实体框架6.1.1模型,entity-framework,sqlite,Entity Framework,Sqlite,我有一个项目,我刚刚用nuget更新过。这将实体框架从6.1更新到6.1.1,并将sqlite更新到1.0.93。我想从我最新的数据库更新我的模型。我按照 1) 来自数据库的模型 2) 选择sqlite数据库 3) 产生 生成后,我收到如下错误消息。我已经安装了1.0.93设计时组件。有人知道到底是什么导致了这个错误吗。项目引用和版本都与上面显示的版本匹配 错误消息: 您的项目引用了最新的实体框架;然而,实体框架数据库提供程序 找不到与此版本兼容的数据连接 更新: 我最终使用PackageMan

我有一个项目,我刚刚用nuget更新过。这将实体框架从6.1更新到6.1.1,并将sqlite更新到1.0.93。我想从我最新的数据库更新我的模型。我按照 1) 来自数据库的模型 2) 选择sqlite数据库 3) 产生

生成后,我收到如下错误消息。我已经安装了1.0.93设计时组件。有人知道到底是什么导致了这个错误吗。项目引用和版本都与上面显示的版本匹配

错误消息:

您的项目引用了最新的实体框架;然而,实体框架数据库提供程序 找不到与此版本兼容的数据连接

更新:

我最终使用PackageManager控制台手动安装了6.1.0

安装软件包EntityFramework-版本6.1.0

然后在我的csporj文件中

软件包\EntityFramework.6.1.1

软件包\EntityFramework.6.1.0

我尝试从数据库中创建EF设计器,并首先从数据库中编写代码,但仍然遇到相同的错误

更新

我已经按照Tom提供的说明进行了操作,感谢您抽出时间进行深入回复,非常感谢。但是我无法让实体框架设计器与SQLite 1.0.93一起工作。我发现:

1) 当我按照Tom的描述从工具菜单添加SQLite数据源时,我看到了SQLite数据提供程序

连接到数据源“>

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

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

4) 添加新数据项,但SQLite未作为提供程序列出

我已经仔细检查了注册表,EF6被附加到不变名称中,SQLite DLL在GAC中注册。我将尝试查看我还能找到什么,但此时我不确定要查找什么。顺便说一句,我尝试了dotConnect,但它对EF 6.1.1也不起作用

更新2


有人知道Entity Framework Designer是否有日志记录选项来找出可能发生的情况吗?

我报告了此问题,并且正在进行修复,并且似乎有一个解决方案可用(我没有测试过它)

[更新:为Visual Studio 2013 UPDATE 4(Pro和Ultimate)提供更简单的解决方案以及Sqlite Providers和EF的最新版本,请查看下面发布的解决方案“broslav”。不知道它是否适用于Express Edition…]

好的,这是一个建议。这不适用于Visual Studio Express版本。 此外,我不知道如何让它为现有项目的更新工作。 这绝对是一种痛苦。 我还没有测试是否需要所有东西,但这应该可以:

首先,不要使用SQLite的NuGet包,而是从以下位置下载程序集安装程序:

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

安装并选择在GAC中安装并安装VS13的设计器

对于以下内容,准确的顺序非常重要

我制作了这些步骤的视频,请参见:

在VS13中创建一个项目。明确地将构建目标设置为framework 4.5.1和x86。保存并构建

接下来,从NuGet.Save和build安装最新的EF6包(6.1.1)

手动添加对已安装SQLite程序集(包括设计器)的引用,在程序集下的引用管理器下,您可以找到用于选择GAC中四个已添加程序集的扩展选项:System.Data.SQLite Core+Designer+for Entity Framework+for LINQ..Save and build

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

添加ADO.NET实体数据模型,选择“从数据库生成”。 您的数据库连接将显示在下拉列表中。将其保留在该列表中,但仍要选择以创建新连接,然后再次选择完全相同的数据库(就像您正在创建新连接一样)。这听起来很愚蠢,但很关键,请参见下图

当我真的以这种方式添加ADO.NET实体数据模型时,它确实出现了令人恼火的错误,但“下一步”按钮是可选的,一切都正常了(令人惊讶)

设计器工作,检索数据和编写数据工作

还没有在另一台机器上测试部署…我使用的是Win7 64位

更改的更新:要获得正确的配置以实际访问数据库,您必须在执行上述所有操作后,从NuGet安装System.Data.SQLite.EF6包,然后添加
添加到App.Config并删除其他提供程序并删除介于
之间的所有内容,否则会出现一些异常。但请注意,这意味着每次要更新EDMX模型时,都必须将App.Config invariantName=“System.Data.SQLite”更改为invariantName=“System.Data.SQLite.EF6”,反之亦然


**这是不是太荒谬了?是的,是的!这让我很头疼…***

我遇到了完全相同的问题——模型设计器向导没有在下拉列表中显示我的sqlite db。我可以通过摆弄sqlite db连接和表来解决它

0a)我通过服务器资源管理器向我的sqlite文件添加了一个连接(sqlite提供程序和服务器显示在服务器资源管理器的“新建连接向导”中,但未显示)
    <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>
<?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>
 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; }
}