gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 12:15:24 25 4
gpt4 key购买 nike

我正在尝试在 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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com