2013-01-24 22 views
11

Ich versuche EF6 alpha und SQLite 1.0.66.0Entity Framework 6 + SQLite

Meine CONFIG-Datei zu verwenden:

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

Wenn ich laufen

using (var dbContext = new TestDbContext()) 
{ 
    if (dbContext.Database.Exists()) 
    { 
     dbContext.Database.Delete(); 
    } 
    dbContext.Database.Create(); 
} 

ich eine bekommen Fehler:

System.InvalidOperationException: System.InvalidOperationException: The 'Instance' member of the Entity Framework provider type 'System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must extend from this class and the 'Instance' member must return the Singleton instance of the provider..

Was mache ich falsch?

+0

Hallo. Ich habe eine funktionierende Lösung in meinem bitbucket-Account veröffentlicht. Ich habe hier nur einen Kommentar geschrieben, weil niemand am Ende der Liste Antworten liest: D Git Adresse: https: //[email protected]/zchpit/sqlitesamples.git – zchpit

Antwort

15

Der System.Data.SQLite Entity Framework-Anbieter muss aktualisiert werden, damit er mit Version 6 des Entity Framework funktioniert. (Siehe Rebuilding EF providers for EF6)

Für SQLite, das ist eine ziemlich einfache Aufgabe:

  1. herunterladen und öffnen Sie das Projekt System.Data.SQLite.Linq
  2. Entfernen Sie den Verweis auf System.Data.Entity.dll
  3. einen Verweis auf EntityFramework.dll Version 6
  4. hinzufügen Update der gebrochene Namespace verweist
  5. dem Provider Rebuild

21.06.2013 Update: Ich habe eine aktualisierte Version des Anbieters in meinem Blog geteilt. Weitere Informationen finden Sie unter System.Data.SQLite on Entity Framework 6.

1

System.Data.SQLite 1.0.91.0 wurde aktualisiert, um EF6 zu unterstützen. Vielen Dank für Brics EF SQLite exzellentes Tutorial und Update. Sie müssen Ihre app.config für die neuen Änderungen aktualisieren, wenn Sie möchten, dass sie mit dem Lernprogramm funktioniert. Ich kann bestätigen, dass das für mich auf VS 2010 gearbeitet hat:

<?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="false"/> 
</configSections> 
<entityFramework> 
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework"> 
    <parameters> 
    <parameter value="v11.0"/> 
    </parameters> 
</defaultConnectionFactory> 
<providers> 
    <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /> 
</providers> 
</entityFramework> 
<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.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" /> 
</DbProviderFactories> 
</system.data> 
<connectionStrings> 
<add name="ChinookContext" connectionString="Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite" providerName="System.Data.SQLite"/> 
</connectionStrings> 
</configuration> 
+0

Diese Lösung löst mein Problem, das sagen, dass ich nicht habe ein kompatibler Provider mit EF6, aber jetzt bekomme ich den Fehler, dass ich die System.Data.SQLite.EF6 im Computer oder in der Konfigurationsdatei nicht registriert habe. Ich habe versucht, die Entwurfskomponenten zu VS2013 zu installieren, weil ich denke, dass die DLL registriert, aber das Problem persistiert. –

+0

@ ÁlvaroGarcía Haben Sie Nuget verwendet, um die neueste Version von EF zu installieren? Überprüfen Sie, ob diese Datei namens System.Data.SQLite.EF6.dll in Ihrem bin-Ordner vorhanden ist. – Drexter

+0

@ ÁlvaroGarcía prüfen, ob dies Ihr Problem behebt. http://stackoverflow.com/questions/21757843/system-data-sqlite-1-0-91-0-and-ef6-0-2?answertab=active#tab-top – Drexter

18

wenn Sie EF 6.1.3 + System.Data.SQLite v1.0.96.0 verwendet, nur einstellen (hinzufügen) die folgenden Erklärungen im Web .config. (Sie können den Unterschied mit einem Textvergleichstool finden, ich habe sie nummeriert).

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

Es funktioniert für mich.

+0

funktioniert auch für mich –

1

Die Ausnahme verschwunden, wenn das NuGet Paket (System.Data.SQLite Version 1.0.94.1) neu installiert mit

Update-Package –reinstall System.Data.SQLite

6

Ich habe Arbeitslösung von EF 6.0 mit SQLite auf meinem Bitbucket Konto: https://[email protected]/zchpit/sqlitesamples.git

oder git https://github.com/zchpit/SQLiteSamples

Sie können Arbeitslösung von diesem Git-Repository herunterladen. In meiner Lösung, verbinde ich mit SQLite:

  • Datenleser
  • Simple.Data
  • EF 6.0

p.s. meine 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> 
Verwandte Themen