我正在嘗試使用EF6 alpha和SQLite 1.0.66.0

我的.config文件:

<connectionStrings>
   <add connectionString="data source=:memory:;" name="TestDbContext" providerName="System.Data.SQLite" />
</connectionStrings>
<entityFramework>
   <providers>
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
   </providers>
</entityFramework>
<runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
     </dependentAssembly>
   </assemblyBinding>
</runtime>
<system.data>
  <DbProviderFactories>
     <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, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
  </DbProviderFactories>
</system.data>

當我跑

<connectionStrings>
   <add connectionString="data source=:memory:;" name="TestDbContext" providerName="System.Data.SQLite" />
</connectionStrings>
<entityFramework>
   <providers>
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
   </providers>
</entityFramework>
<runtime>
   <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
     </dependentAssembly>
   </assemblyBinding>
</runtime>
<system.data>
  <DbProviderFactories>
     <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, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
  </DbProviderFactories>
</system.data>

我收到一個錯誤:

System.InvalidOperationException:System.InvalidOperationException:實體框架提供程序類型'System.Data.SQLite.SQLiteFactory,System.Data.SQLite,Version = 1.0.66.0,Culture = neutral,PublicKeyToken = db937bc2d44ff139'的'Instance'成員沒有返回一個繼承自'System.Data.Entity.Core.Common.DbProviderServices'的對象。實體框架提供程序必須從此類擴展,並且“實例”成員必須返回提供程序的Singleton實例。

我究竟做錯了什麼?

熱門答案

如果您使用的是EF 6.1.3 + System.Data.SQLite v1.0.96.0,只需在web.config中調整(添加)以下聲明即可。 (你可以找到一些文本比較工具的差異,我已經編號了)。

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

        <!-- 1. Solves SQLite error of "Unable to find the requested .Net Framework Data Provider."-->
        <provider invariantName="System.Data.SQLite" 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" /> 

        <!-- 2. Solves SQLite error of "Unable to find the requested .Net Framework Data Provider."-->
        <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>

這個對我有用。




許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因
許可下: CC-BY-SA with attribution
不隸屬於 Stack Overflow
這個KB合法嗎? 是的,了解原因