簡體   English   中英

EF 6 和 SQLite 1.0.105.2 的“未找到實體框架提供程序”

[英]'No Entity Framework provider found' for EF 6 and SQLite 1.0.105.2

我已經嘗試了一些關於以前版本的類似問題的答案,但似乎都不起作用:

  • 向 App.config 添加第三個提供程序 (Sqlite)。
  • 將連接字符串提供程序從 Sqlite.EF56 更改為 Sqlite。

什么有效:從數據庫更新(在 Sqlite Studio 中更改后)。

什么不起作用:從更新的模型生成數據庫。

錯誤消息:未找到具有不變名稱“System.Data.Sqlite.EF6”的 ADO.NET 提供程序的實體框架提供程序。

我正在使用 Visual Studio 2015。我已經安裝了sqlite-netFx46-setup-bundle-x86-2015-1.0.105.2.exe (用於視覺設計器),然后添加了 NuGet 包,如下所示:

<package id="EntityFramework" version="6.1.3" targetFramework="net45" />   
<package id="System.Data.SQLite" version="1.0.105.2" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.105.2" targetFramework="net45" />    
<package id="System.Data.SQLite.EF6" version="1.0.105.2" targetFramework="net45" />
<package id="System.Data.SQLite.Linq" version="1.0.105.2" targetFramework="net45" />

我的 App.config:

<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.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="data03Entities" connectionString="metadata=res://*/Data.Data03.csdl|res://*/Data.Data03.ssdl|res://*/Data.Data03.msl;provider=System.Data.SQLite.EF6;provider connection string='data source=&quot;C:\Users\Frederik\Documents\Data\data03.db&quot;'" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

確保DbProviderFactoriesentityFramework部分存在於您的主項目(啟動項目)配置文件中。 您可能在單獨的項目中擁有數據訪問權限。

在您的配置文件中:

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

您需要添加提供者節點

<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

正如許多開發人員報告的那樣,它也是必要的。 我也有過這樣的經歷。

還要確保您的連接字符串引用提供程序“System.Data.SQLite”而不是“System.Data.SQLite.EF6”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM