2013-01-24 10 views
11

Próbuję użyć EF6 alfa i SQLite 1.0.66.0Entity Framework 6 + SQLite

Mój plik .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> 

Kiedy biegnę

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

Dostaję błąd:

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

Co robię źle?

+0

Witam. Umieściłem działające rozwiązanie na moim koncie bitbucket. Właśnie napisałem komentarz tutaj, ponieważ nikt nie czyta answares na dole listy: Adres D Git: https: //[email protected]/zchpit/sqlitesamples.git – zchpit

Odpowiedz

15

Dostawca System.Data.SQLite Entity Framework będzie musiał zostać zaktualizowany, aby działał z wersją 6 Entity Framework. (Patrz Rebuilding EF providers for EF6)

SQLite, jest dość trywialne zadanie:

  1. Pobierz i otwórz projekt System.Data.SQLite.Linq
  2. Usuń odniesienie do System.Data.Entity.dll
  3. Dodaj odwołanie do wersji EntityFramework.dll 6
  4. zaktualizować złamany nazw odwołuje
  5. Rebuild dostawcę

21 czerwca 2013 Aktualizacja: Udostępniłem zaktualizowaną wersję dostawcy na moim blogu. Aby uzyskać więcej informacji, patrz System.Data.SQLite on Entity Framework 6.

1

System.Data.SQLite 1.0.91.0 został zaktualizowany do obsługi EF6. Wielkie dzięki za świetny samouczek i aktualizację Brice's EF SQLite. Musisz zaktualizować plik app.config, aby wprowadzić nowe zmiany, jeśli chcesz, aby działał z samouczkiem. Mogę potwierdzić, że pracował dla mnie na VS 2010:

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

To rozwiązanie rozwiązuje mój problem, który mówi mi, że nie mam kompatybilny dostawca z EF6, ale teraz dostaję błąd, że nie zarejestrowałem System.Data.SQLite.EF6 w komputerze lub w pliku konfiguracyjnym. Próbowałem zainstalować składniki projektu do VS2013, ponieważ myślę, że zarejestrować DLL, ale problem wydaje się. –

+0

@ ÁlvaroGarcía Czy użyłeś Nuget do zainstalowania najnowszej wersji EF? Sprawdź i sprawdź, czy ten plik o nazwie System.Data.SQLite.EF6.dll znajduje się w folderze bin. – Drexter

+0

@ ÁlvaroGarcía Sprawdź, czy to rozwiąże problem. http://stackoverflow.com/questions/21757843/system-data-sqlite-1-0-91-0-and-ef6-0-2?answertab=active#tab-top – Drexter

18

jeśli użyto EF 6.1.3 + System.Data.SQLite v1.0.96.0, po prostu dostosować (ADD) następujące deklaracje w internecie .config. (możesz znaleźć różnicę w porównaniu z narzędziem do porównywania tekstu, mam ich ponumerowane).

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

To działa dla mnie.

+0

działa także dla mnie –

1

Wyjątkiem zniknął podczas ponownej instalacji pakietu Nuget (System.Data.SQLite wersja 1.0.94.1) z

Update-Package –reinstall System.Data.SQLite

6

umieścić roztwór roboczy EF 6.0 z SQLite na moim rachunku Bitbucket: https://[email protected]/zchpit/sqlitesamples.git

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

Możesz pobrać działające rozwiązanie z tego repozytorium git. W moim rozwiązanie, podłączyć do SQLite przez:

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