SQLite和实体框架6如何结合

时间:2016-02-09 11:59:39

标签: entity-framework sqlite

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

  

'实例'实体框架提供程序类型的成员' System.Data.SQLite.SQLiteFactory,System.Data.SQLite,Version = 1.0.99.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139'没有返回继承自System.Data.Entity.Core.Common.DbProviderServices'的对象。实体框架提供者必须从此类继承并且实例'成员必须返回提供者的单例实例。这可能是因为提供商不支持Entity Framework 6或更高版本;

您能否提示一下可能导致问题的原因?非常感谢!

我的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>

我安装了以下组件:

  • EF 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

1 个答案:

答案 0 :(得分:4)

最后我找出了问题。

  1. 删除sqlite niget软件包
  2. 已安装的EF6包
  3. 已安装的nuget包System.Data.SQLite 1.0.99(它将安装所有必需的依赖项)
  4. 使用下面列出的app.cong文件进行了一些更正

    <?xml version="1.0" encoding="utf-8"?>
    

                                                                                                                               

  5. 并确保:

    1. 参考选项卡中的SQLite dll引用项目中的dll。如果你从官方网站安装了SQLite,它会引用一些参考文件......
    2. 安装软件包后检查app.config文件。确保DBprovider,EntityFramework和Connecstion字符串部分算在上面列出。
    3. 在模型类中使用[Table&#34; Artist&#34;]和[&#34; Key&#34;]等数据解析键。 (包括使用System.ComponentModel.DataAnnotations;使用System.ComponentModel.DataAnnotations.Schema;)
    4. 祝你好运! 希望这对我们中的一些人有用