Mi rendo conto che ci sono già parecchie domande simili su questo argomento, ma molte di esse provengono da una versione precedente di SQLite che non supportava completamente EF 6 per quanto ne so. Ho provato innumerevoli suggerimenti da questi thread e sto facendo qualcosa di sbagliato o qualcosa deve essere cambiato.
Utilizzo VS 2013, con targeting per .NET 4.5.1 e ho installato il pacchetto sqlite-netFx451-setup-bundle-x86-2013-1.0.96.0.exe dalla pagina di download system.data.sqlite.org , oltre che Pacchetto System.Data.SQLite EF6 da NuGet Manager (che installa EF6).
Di seguito è il mio file App.config corrente (è praticamente intatto tranne che ho provato ad aggiungere le variabili Version, Culture e Public key al tipo):
<?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>
E il mio 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>
Se faccio qualcosa come il tentativo di generare un database dal modello, vedo il seguente errore:
Nessun provider di Entity Framework trovato per il provider ADO.NET con nome invariante "System.Data.SQLite.EF6". Assicurati che il provider sia registrato nella sezione "entityFramework" ...
Ho provato a risolvere il problema con il file App.config e ad aggiungere altri provider e provider come suggerito da vecchi thread, ma senza risultati.
Come posso risolvere questo problema? Qualsiasi aiuto è molto apprezzato!
Modifica: sono riuscito a farlo funzionare abbastanza bene da utilizzare un primo approccio al database. Ecco le parti rilevanti del mio file 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>
Sto usando EF 6.1.2 e System.Data.SQLite 1.0.96.0.
Ho risolto lo stesso errore con solo aggiungere una singola riga in App.config
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
PS: aggiungi il provider
a <configuration>
>> <entityFramework>
>> <providers>
Ecco una app.config funzionante
<?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>