45

I realize there are already several similar questions on this topic, but many of them are from older version of SQLite which did not fully support EF 6 as far as I am aware. I have tried countless suggestions from these threads and am either doing something wrong or something must have changed.

I am using VS 2013, targeting .NET 4.5.1 and have installed the sqlite-netFx451-setup-bundle-x86-2013-1.0.96.0.exe package from the system.data.sqlite.org download page, as well as the System.Data.SQLite EF6 package from the NuGet Manager (which installs EF6).

Below is my current App.config file (it is pretty much untouched except I tried adding the Version, Culture, and Public key variables to the type):

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

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

If I do something such as attempt to Generate a Database from Model I see the following error:

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite.EF6'. Make sure the provider is registered in the 'entityFramework' section...

I've tried messing around the the App.config file and adding other providers and providers as old threads have suggested but to no avail.

How do I fix this problem? Any help is greatly appreciated!

Edit: I managed to get it to work well enough to use a database first approach. Here is the relevant parts of my App.config file:

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

I'm using EF 6.1.2 and System.Data.SQLite 1.0.96.0.

Simon
  • 536
  • 1
  • 7
  • 13
  • I had to *also* add `System.Data.SQLite` – Ian McLaird Jun 01 '17 at 20:41
  • I have the same problem but I don't understand how you get that xml into your app.config in the first place. I don't need any of that, no app.config except a connection string for SqlServer and EF queries are running fine. How then, did you get all that `DbProviderFactories` stuff into your config, do I need it and if so, how can I get it in there without copying old config from the wrong place? – PandaWood Mar 29 '23 at 02:18

6 Answers6

102

I solved same error with just add a single line in App.config

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

PS: Add provider to <configuration> > <entityFramework> > <providers>

Amir Astaneh
  • 2,152
  • 1
  • 20
  • 20
13

Here is a working 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>
Paul
  • 397
  • 5
  • 9
6

I finally got it too work

I'm using : EF 6.1.3 http://www.microsoft.com/en-us/download/details.aspx?id=40762 and System.Data.SQLite 1.0.96.0 sqlite-netFx451-setup-bundle-x86-2013-1.0.96.0.exe

I followed the description written in: Database first create entity framework 6.1.1 model using system.data.sqlite 1.0.93 (in this description a nuget package of entity framwork is installed -i did it too)

For the app.config file i used these fixes: https://stackoverflow.com/a/24324212/885349 (written by tomexou)

Finally SQLite Connector wasn't shown in the ADO.Net Entity Data Model Mapper

The missing link was the \bin folder. I had to set the "Copy Local" = true setting for following dlls:

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

Only for completeness - added through Nuget and also in \bin folder

  • EntityFramework
  • EntityFramework.SqlServer

And the SQLite Connection was shown...

Community
  • 1
  • 1
3

Try these tweaks:

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

See Entity Framework 6 + SQLite

Community
  • 1
  • 1
Steve Greene
  • 12,029
  • 1
  • 33
  • 54
  • I'm still seeing the same error. Just to clarify, I should leave the other entry for SQLite in the section right? So there is one for System.Data.SQLite.EF6 and System.Data.SQLite. Either way, it isn't working. I'm able to see/create a data connection as I was before, but it fails on execution. – Simon Mar 18 '15 at 19:41
  • My issue came after updating, so I changed my config as shown in the link. What does your connection string look like? – Steve Greene Mar 18 '15 at 19:47
  • metadata=res://*/DbModel.csdl|res://*/DbModel.ssdl|res://*/DbModel.msl;provider=System.Data.SQLite.EF6;provider connection string="data source=C:\sqlite_test\testDb" – Simon Mar 18 '15 at 19:53
  • My provider is just System.Data.SQLite; Not sure that would matter. – Steve Greene Mar 18 '15 at 20:16
  • If I remove the System.Data.SQLite invariant from , SQLite is no longer shown as a Data source in the Generate Database Wizard datasource window though. I'm at a bit of a loss on this one. – Simon Mar 18 '15 at 20:29
3

After searching for a week i believe this problem is a feature in development by the sqlite team.

More information can be found here SQLite connection not appearing in Entity Data Model Wizard

edit: Maybe looking into some different providers might seem worthwhile. Although i have not tested this myself, http://www.devart.com/dotconnect/ offers some promising alternatives and states EF compatibility.

Community
  • 1
  • 1
ImP
  • 175
  • 1
  • 4
  • 12
  • Thanks for the response. I did end up getting it functioning well enough (without some of the VS design tools) to do what I needed, but hopefully it is easier to setup in future versions. – Simon Apr 02 '15 at 22:31
  • May i ask what you did to solve your problem, maybe it can help me with mine :) – ImP Apr 02 '15 at 22:37
  • To be honest, it was a few weeks ago and a lot of fiddling. I decided to use a database first approach as it was a relatively simple app, and that did work. I'll post my App.config properties as an edit above. Hopefully that helps! Good luck! – Simon Apr 02 '15 at 22:42
-2
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);
    }
}