SQLite with EntityFramework - Problems with database creation

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
danielzimmermann
Posts: 1
Joined: Wed 18 Mar 2015 07:02

SQLite with EntityFramework - Problems with database creation

Post by danielzimmermann » Wed 18 Mar 2015 07:20

Hello all

I am evaluating dotConnect for SQLite with EntityFramework. I did a sample project according to the official sample of this forum and it did not work so far.

My Config-File looks like this:

Code: Select all


<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <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.96.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
      <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" />-->

      <remove invariant="Devart.Data.SQLite" />
      <add name="Devart SQLite Provider Factory" invariant="Devart.Data.SQLite" description="Devart ProviderFactory that supports table generation with Entity Framework" type="Devart.Data.SQLite.SQLiteProviderFactory, Devart.Data.SQLite, Version=5.2.359.0, Culture=neutral, PublicKeyToken=09af7300eec23701"  />
    </DbProviderFactories>
  </system.data>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <!--<defaultConnectionFactory type="SqliteEval.EntityFramework.ConnectionFactory, SqliteEval">
      --><!--<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" />-->
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <provider invariantName="Devart.Data.SQLite" type="Devart.Data.SQLite.Entity.SQLiteEntityProviderServices, Devart.Data.SQLite.Entity, Version=5.2.359.6, Culture=neutral, PublicKeyToken=09af7300eec23701"></provider>
    </providers>
  </entityFramework>

  <connectionStrings>
    <clear />
    <add name="DatabaseContext" connectionString="DataSource=D:\data.db;Version=3" providerName="System.Data.SQLite" />
  </connectionStrings>
</configuration>

and my Code is quite simple:

Code: Select all

        static void Main(string[] args)
        {
            // string connectionString = @"DataSource = D:\data.db;Version=3;";
            File.Delete("D://data.db");

            Database.DefaultConnectionFactory = new SqLiteConnectionFactory("D://data.db", null);

            Database.SetInitializer(new CreateDatabaseIfNotExists<DatabaseContext>());

            using (DatabaseContext databaseContext = new DatabaseContext())
            {
                Console.WriteLine("ConnectionString: {0}", databaseContext.Database.Connection.ConnectionString);
                databaseContext.Database.Initialize(true);
            }
        }
I tried many different things and also downloaded one example I found here in the forum, but it did not work either. The database file is created, but there is no data in it.

Version information:

dotConnect:
Downloaded Professional Version 5.2 yesterday (from here: http://www.devart.com/dotconnect/sqlite/download.html)

SQLite
Nuget Package "System.Data.SQLite" version 1.0.96 (x86/x64)

EntityFramework
Nuget Package "EntityFramework" Version 6.1.3

It would be nice if anybody could help me.
Regards Daniel

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

Re: SQLite with EntityFramework - Problems with database creation

Post by Shalex » Thu 19 Mar 2015 08:52

Your current connection string uses System.Data.SQLite. dotConnect for SQLite doesn't depend on System.Data.SQLite (you can remove it). The *.config file should look like this:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.data>
    <DbProviderFactories>
      <remove invariant="Devart.Data.SQLite" />
      <add name="Devart SQLite Provider Factory" invariant="Devart.Data.SQLite" description="Devart ProviderFactory that supports table generation with Entity Framework" type="Devart.Data.SQLite.SQLiteProviderFactory, Devart.Data.SQLite, Version=5.2.359.0, Culture=neutral, PublicKeyToken=09af7300eec23701"  />
    </DbProviderFactories>
  </system.data>
  <entityFramework>
    <providers>
      <provider invariantName="Devart.Data.SQLite" type="Devart.Data.SQLite.Entity.SQLiteEntityProviderServices, Devart.Data.SQLite.Entity, Version=5.2.359.6, Culture=neutral, PublicKeyToken=09af7300eec23701"></provider>
    </providers>
  </entityFramework>
  <connectionStrings>
    <clear />
    <add name="DatabaseContext" connectionString="DataSource=D:\data.db;Fail If Missing=false;" providerName="Devart.Data.SQLite" />
  </connectionStrings>
</configuration>
If this doesn't help, specify the exact text of the error and its call stack.

JIC: refer to
http://blog.devart.com/entity-framework ... force.html
http://www.devart.com/dotconnect/sqlite ... pport.html

Post Reply