Entity Framework 6 + SQLite Entity Framework 6 + SQLite sqlite sqlite

Entity Framework 6 + SQLite


if you used EF 6.1.3 + System.Data.SQLite v1.0.96.0, just adjust(add) the following declarations in the web.config. (you can find the difference with some text-compare tool, i have numbered them).

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

It works for me.


The System.Data.SQLite Entity Framework provider will need to be updated to work with version 6 of the Entity Framework. (See Rebuilding EF providers for EF6)

For SQLite, this is a fairly trivial task:

  1. Download and open the System.Data.SQLite.Linq project
  2. Remove the reference to System.Data.Entity.dll
  3. Add a reference to EntityFramework.dll version 6
  4. Update the broken namespace references
  5. Rebuild the provider

Jun 21, 2013 Update:I've shared an updated version of the provider on my blog. See System.Data.SQLite on Entity Framework 6 for more information.


I put working solution of EF 6.0 with Sqlite on my Bitbucket account: https://zchpit@bitbucket.org/zchpit/sqlitesamples.git

or githttps://github.com/zchpit/SQLiteSamples

You can download working solution from that git repository. In my solution, I connect to Sqlite by:

  • Data Reader
  • Simple.Data
  • EF 6.0

p.s. my App.config

<?xml version="1.0"?><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="true" />  </configSections>  <startup useLegacyV2RuntimeActivationPolicy="true">    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client" />  </startup>  <runtime>    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">      <dependentAssembly>        <assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />        <bindingRedirect oldVersion="0.0.0.0-1.0.96.0" newVersion="1.0.96.0" />      </dependentAssembly>    </assemblyBinding>  </runtime>  <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>  <connectionStrings>    <add name="SqlLiteContext" connectionString="Data Source=|DataDirectory|MyDatabase.sqlite" providerName="System.Data.SQLite" />  </connectionStrings>  <entityFramework>    <providers>      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>    </providers>    <defaultConnectionFactory type="System.Data.SQLite.SQLiteFactory, EntityFramework">      <parameters>        <!---parameter value="v11.0" />-->      </parameters>    </defaultConnectionFactory>  </entityFramework></configuration>