EF 6 and SQLite connection -

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Jonathan.Mitchell
Posts: 3
Joined: Tue 04 Jun 2013 12:42

EF 6 and SQLite connection -

Post by Jonathan.Mitchell » Tue 04 Jun 2013 12:59

I am trying to build an ultra simple EF6 project on .NET 4.0 in C# on Win 7. The ultimate intention is to get this simple console app to run on Mono under OS X.

At present under Windows the app fails with:
Exception: System.InvalidOperationException: The 'Instance' member of the Entity
Framework provider type 'Devart.Data.SQLite.SQLiteProviderFactory, Devart.Data.
SQLite, Version=4.6.252.0, Culture=neutral, PublicKeyToken=09af7300eec23701' did
not return an object that inherits from 'System.Data.Entity.Core.Common.DbProvi
derServices'. Entity Framework providers must extend from this class and the 'In
stance' member must return the Singleton instance of the provider.
at System.Data.Entity.Config.ProviderServicesFactory.GetInstance(Type provide
rType)
at System.Data.Entity.Config.ProviderServicesFactory.GetInstance(String provi
derTypeName, String providerInvariantName)
The Devart EF samples provided with the SQLite data connector run okay, so presumably assemblies are installed okay.

I have referenced the following assemblies and copy them into the executable folder as part of the build. I do this as I don't want to rely on the GAC.

Code: Select all

Devart.Data
Devart.Data.Linq
Devart.Data.SQLite
Devart.Data.SQLite.Entity  << EF 6 version
Devart.Data.SQLite.Linq
EntityFramework << EF 6 b1
I also copy sqlite3.dll into the output folder - I presume this is required.

The app.config file is so:

Code: Select all

<?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>
  
  <entityFramework>
    <providers>
      <provider invariantName="Devart.Data.SQLite" type="Devart.Data.SQLite.SQLiteProviderFactory, Devart.Data.SQLite" />
    </providers>
  </entityFramework>

  <system.data>
    <DBproviderFactories>
      <remove invariant="Devart.Data.SQLite" />
      <add name="dotConnect for SQLite" invariant="Devart.Data.SQLite" description="Devart dotConnect for SQLite" type="Devart.Data.SQLite.SQLiteProviderFactory, Devart.Data.SQLite" />"
    </DBproviderFactories>
  </system.data>
  
  </configuration>
Any suggestions would be appreciated.

Jonathan.Mitchell
Posts: 3
Joined: Tue 04 Jun 2013 12:42

Re: EF 6 and SQLite connection -

Post by Jonathan.Mitchell » Tue 04 Jun 2013 20:57

I am still looking for enlightenment to the problem described above.

Using VS 2012 I can run my simple console app fine when targetting EF 5.
Moving to EF 6 leads to failure.

When attempting to use EF6 I use the EF 6 B1 package in place of EF 5.
In addition I upgrade the app.config as shown above.

I know that changes are required to the provider model for EF 6.
https://entityframework.codeplex.com/wi ... 0use%20EF6

Using DotPeek I can see that for Devart.Data.SQLite 4.6.252.0 SQLiteprovideFactory derives from System.Data.Common.DbProviderFactory which is no doubt the source of the problem above. However there doesn't seem to be an EF6 specific version of Devart.Data.SQLite.

The docs state that a specific version of Devart.System.SQLite.Entity exists for EF 6 - See http://blogs.devart.com/dotconnect/enti ... force.html. But my issue seems to reside in Devart.Data.SQLite rather than in the Entity assembly.

I am just having versioning issues (which I would be glad to get resolved) or is there a real issue here with EF 6 SQLite support?

Shalex
Site Admin
Posts: 8247
Joined: Thu 14 Aug 2008 12:44

Re: EF 6 and SQLite connection -

Post by Shalex » Fri 07 Jun 2013 10:12

1. dotConnect for SQLite supports Entity Framework 6 Beta 1 starting from the latest (4.6.257) build: http://www.devart.com/dotconnect/sqlite ... story.html. Please install it.

2. The dotConnect for SQLite registration for Entity Framework 6 should look like this:

Code: Select all

<?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>
  <entityFramework>
    <providers>
      <provider invariantName="Devart.Data.SQLite" type="Devart.Data.SQLite.Entity.SQLiteEntityProviderServices, Devart.Data.SQLite.Entity, Version=4.6.257.6, Culture=neutral, PublicKeyToken=09af7300eec23701" >
        <!--migrationSqlGenerator type="Devart.Data.SQLite.Entity.Migrations.SQLiteEntityMigrationSqlGenerator, Devart.Data.SQLite.Entity, Version=4.6.257.6, Culture=neutral, PublicKeyToken=09af7300eec23701" /-->
      </provider>
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="Devart.Data.SQLite" />
      <add name="dotConnect for SQLite" invariant="Devart.Data.SQLite"
        description="Devart dotConnect for SQLite" type="Devart.Data.SQLite.SQLiteProviderFactory, Devart.Data.SQLite, Version=4.6.257.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
    </DbProviderFactories>
  </system.data>
</configuration>
There is a bug with setting migrationSqlGenerator via *.config in Entity Framework 6. Please set it in the code: http://blogs.devart.com/dotconnect/enti ... Migrations.

3. Add references to the following assemblies in your project:
\Program Files (x86)\Devart\dotConnect\SQLite\Devart.Data.dll
\Program Files (x86)\Devart\dotConnect\SQLite\Devart.Data.SQLite.dll
\Program Files (x86)\Devart\dotConnect\SQLite\Entity\EF6\Devart.Data.SQLite.Entity.dll

Jonathan.Mitchell
Posts: 3
Joined: Tue 04 Jun 2013 12:42

Re: EF 6 and SQLite connection -

Post by Jonathan.Mitchell » Mon 10 Jun 2013 11:07

Thanks for the update and the corrected app.config. My console app now succeeds using EF6 b1.

My error, now obvious, was in the app.config entityFramework provider definition. EF6 requires a System.Data.Entity.Core.Common.DBProviderServices instance. This is provided explicitly by Devart.Data.SQLite.Entity.SQLiteProviderServices.

Post Reply