簡體   English   中英

對於EF 6和SQLite 1.0.96.0,“找不到實體框架提供程序”

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

我知道在這個主題上已經有幾個類似的問題了,但是其中很多都來自SQLite的舊版本,據我所知,它並沒有完全支持EF 6。 我已經嘗試過這些線程的無數建議,要么是做錯了,要么是必須改變的。

我正在使用VS 2013,面向.NET 4.5.1,並已從system.data.sqlite.org下載頁面安裝了sqlite-netFx451-setup-bundle-x86-2013-1.0.96.0.exe軟件包,以及來自NuGet Manager的System.Data.SQLite EF6包(安裝EF6)。

下面是我當前的App.config文件(除了我嘗試將Version,Culture和Public鍵變量添加到類型中之外,它幾乎沒有變化):

<?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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
  </startup>
  <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, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </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, Version=1.0.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139"
      />
    </DbProviderFactories>
  </system.data>
</configuration>

而我的packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.1.2" targetFramework="net451" />
  <package id="System.Data.SQLite.EF6" version="1.0.96.0" targetFramework="net451" />
</packages>

如果我執行某些操作,例如嘗試從模型I生成數據庫,請看以下錯誤:

沒有為ADO.NET提供程序找到具有不變名稱“System.Data.SQLite.EF6”的實體框架提供程序。 確保提供商已在“entityFramework”部分注冊...

我已經嘗試弄亂App.config文件並添加其他提供商和提供商,如舊線程建議但無濟於事。

我該如何解決這個問題? 任何幫助是極大的贊賞!

編輯:我設法讓它運行良好,使用數據庫第一種方法。 以下是我的App.config文件的相關部分:

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

<DbProviderFactories>
     <remove invariant="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" />
     <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>

我正在使用EF 6.1.2和System.Data.SQLite 1.0.96.0。

我在App.config中添加了一行就解決了同樣的錯誤

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

PS:將provider添加到<configuration> >> <entityFramework> >> <providers>

這是一個有效的app.config

<?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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>

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

  <connectionStrings>
    <!-- use AppDomain.SetData to set the DataDirectory -->
    <add name="MapDbConnectionStr" connectionString="Data Source=|DataDirectory|MapDb.sqlite" providerName="System.Data.SQLite" />
  </connectionStrings>

  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite.EF6" />
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
  </system.data>



</configuration>

我終於得到了它的工作

我正在使用:EF 6.1.3 http://www.microsoft.com/en-us/download/details.aspx?id=40762和System.Data.SQLite 1.0.96.0 sqlite-netFx451-setup-bundle-x86 -2013-1.0.96.0.exe

我按照寫的描述: 數據庫首先使用system.data.sqlite 1.0.93創建實體框架6.1.1模型 (在此描述中安裝了實體框架的nuget包-i也做了)

對於app.config文件,我使用了以下修復程序: https ://stackoverflow.com/a/24324212/885349(由tomexou編寫)

最后,ADO.Net實體數據模型映射器中未顯示SQLite Connector

缺少的鏈接是\\ bin文件夾。 我必須為以下dll設置“Copy Local”= true設置:

  • SQLite.Designer
  • System.Data.SQLite
  • System.Data.SQLite.EF6
  • System.Data.SQLite.Linq

僅為了完整性 - 通過Nuget和\\ bin文件夾添加

  • 的EntityFramework
  • EntityFramework.SqlServer

並顯示了SQLite連接......

試試這些調整:

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

<system.data>
    <DbProviderFactories>
        <remove invariant="System.Data.SQLite.EF6" />
        <add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
    </DbProviderFactories>
</system.data>

請參閱實體框架6 + SQLite

搜索一周后,我相信這個問題是sqlite團隊開發的一個功能。

可以在此處找到更多信息SQLite連接未出現在實體數據模型向導中

編輯:也許看一些不同的提供商可能看起來值得。 雖然我自己沒有對此進行過測試,但http://www.devart.com/dotconnect/提供了一些有前景的替代方案並說明了EF的兼容性。

public class EFConfiguration : DbConfiguration
{
    public EFConfiguration()
    {
        SetDefaultConnectionFactory(new LocalDbConnectionFactory("v.11"));

        //HACK
        var EF6ProviderServicesType = typeof(System.Data.SQLite.EF6.SQLiteProviderFactory).Assembly.DefinedTypes.First(x => x.Name == "SQLiteProviderServices");
        var EF6ProviderServices = (DbProviderServices)Activator.CreateInstance(EF6ProviderServicesType);
        SetProviderServices("System.Data.SQLite.EF6", EF6ProviderServices);
        SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
        SetProviderFactory("System.Data.SQLite.EF6", System.Data.SQLite.EF6.SQLiteProviderFactory.Instance);
        SetProviderFactory("System.Data.SQLite", System.Data.SQLite.SQLiteFactory.Instance);
    }
}

暫無
暫無

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

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