entity-framework - SQLite 和 Entity Framework 6 如何结合

标签 entity-framework sqlite

我正在尝试在 SQLite (http://brice-lambson.blogspot.ru/2012/10/entity-framework-on-sqlite.html) 上完成 Entity Framework 5。我已经安装了 SQLite 和 EF6。但是我得到了一个错误:

The 'Instance' member of the Entity Framework provider type 'System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later;



你能给我一个提示可能导致问题的原因吗?非常感谢!

我的 app.config文件如下所示:
<configuration>
    <configSections>
        <section name="entityFramework" 
                 type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </configSections>
    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
    </startup>
    <entityFramework>
        <defaultConnectionFactory type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
        <providers>
            <provider invariantName="System.Data.SQLite" 
                      type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
            <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.data>
        <DbProviderFactories>
            <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" />
            <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" /></DbProviderFactories>
    </system.data>
    <connectionStrings>
        <add name="ChinookContext" 
             connectionString="Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite"
             providerName="System.Data.SQLite"/>
    </connectionStrings>
</configuration>

我安装了以下组件:
  • 英孚 6.0.0
  • System.Data.SQLite 1.0.99
  • System.Data.SQLite.Core 1.0.99
  • System.Data.SQLite.EF6 1.0.99
  • System.Data.SQLite.Linq 1.0.99
  • 最佳答案

    最后我弄清楚了这个问题。

  • 删除 sqlite niget 包
  • 已安装 EF6 包
  • 已安装 nuget pack System.Data.SQLite 1.0.99(它将安装所有必要的依赖项)
  • 对下面列出的 app.cong 文件进行了一些更正
    <?xml version="1.0" encoding="utf-8"?>
    




























  • 并确保:
  • 引用选项卡中的 SQLite dll 指的是项目中的 dll。如果您从官方网站安装 SQLite,它会使引用变得困惑...
  • 安装包后检查 app.config 文件。确保 DBprovider、EntityFramework 和 Connect 字符串部分在上面列出。
  • 在模型类中使用数据分析键,如 [Table"Artist"] 和 ["Key"]。 (包括使用 System.ComponentModel.DataAnnotations;使用 System.ComponentModel.DataAnnotations.Schema;)

  • 祝你好运!
    希望这对我们/你们中的一些人有用

    关于entity-framework - SQLite 和 Entity Framework 6 如何结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35291533/

    相关文章:

    c# - 在多对多关系中定义 FK 名称

    c# - 错误 : "Spatial types and functions are not available for this provider"

    database - sqlite 中的外键是存储整个值,还是仅存储指向其他表中实际值的指针?

    sql-server - 无法打开登录请求的数据库 <数据库>。登录失败。用户 <user> 登录失败

    c# - 使用 LINQ to SQL 进行分页

    android - 如何在android中按日期获取通话记录?

    android - 获取错误 : Caused by: android. database.sqlite.SQLiteException:接近 "TABLENAME"语法错误(代码 1)编译 SELECT 查询

    python - Python 尝试使用一些 Twitter 数据更新 Sqlite3 数据库时数据类型不匹配

    c# - Entity Framework 不将数据刷新到数据库

    mysql - 核心数据和 MySQL