Riddik
Riddik

Reputation: 2983

How SQLite and Entity Framework 6 combine

I am trying to get done with Entity Framework 5 on SQLite (http://brice-lambson.blogspot.ru/2012/10/entity-framework-on-sqlite.html). I have installed SQLite and EF6. However I got an error :

The 'Instance' member of the Entity Framework provider type 'System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.99.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later;

Can you please give me a hint what may cause the issue? Thanks a lot!

My app.config file looks like this:

<configuration>
    <configSections>
        <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>
        <defaultConnectionFactory type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6"/>
        <providers>
            <provider invariantName="System.Data.SQLite" 
                      type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
            <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" />
        </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" />
            <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>
    <connectionStrings>
        <add name="ChinookContext" 
             connectionString="Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite"
             providerName="System.Data.SQLite"/>
    </connectionStrings>
</configuration>

I have following components installed:

Upvotes: 1

Views: 677

Answers (1)

Riddik
Riddik

Reputation: 2983

Finally i figure out the issue.

  1. Remove sqlite niget packages
  2. Installed EF6 pack
  3. Installed nuget pack System.Data.SQLite 1.0.99 (It will install all necessary dependencies)
  4. did some correction with app.cong file listed below

    <?xml version="1.0" encoding="utf-8"?>
    

And make sure:

  1. SQLite dlls in references tab refer to dlls within your project. If you installed SQLite from the official site it make some mess with references...
  2. Check app.config file after installing packages. Make sure DBprovider, EntityFramework and Connecstion string sections mathces to list above.
  3. Use data anatation keys like [Table"Artist"] and ["Key"] in model classes. (include using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema;)

Good luck! Hope this will be usefull some of us/you

Upvotes: 4

Related Questions