Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Entity Framework CTP5 work with SQLite?

I am having a very hard time in using the SQLite db with EF CTP5. I was just trying to execute this MSDN example with SQLite. But at the line

var food = db.Categories.Find("FOOD");

I am getting a runtime exception:

System.Data.SQLite.SQLiteException (0x80004005): SQLite errorno such table: Categories

Note: The app.config file has to be modified and is as follows:

App.config

<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v4.0" />
  </startup>
  <runtime>
    <generatePublisherEvidence enabled="false" />
  </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>
  <connectionStrings>
    <add name="ProductContext" connectionString="Data Source=D:\CodeFirst.db;Version=3;New=True;" providerName="System.Data.SQLite" />
  </connectionStrings>
</configuration>
like image 812
Anindya Chatterjee Avatar asked Feb 04 '11 17:02

Anindya Chatterjee


People also ask

Can I use Entity Framework with SQLite?

This database provider allows Entity Framework Core to be used with SQLite. The provider is maintained as part of the Entity Framework Core project.

Does SQLite support migrations?

Unlike other databases, SQLite doesn't include a procedural language. Because of this, there is no way to generate the if-then logic required by the idempotent migration scripts. If you know the last migration applied to a database, you can generate a script from that migration to the latest migration.

Does SQLite support .NET core?

To install EF Core, you install the package for the EF Core database provider(s) you want to target. This tutorial uses SQLite because it runs on all platforms that . NET Core supports.


2 Answers

It seems to me that current SQLite.net does not support Entity Framework CTP5 code first. Will have to wait for that to happen.

like image 116
Anindya Chatterjee Avatar answered Sep 28 '22 02:09

Anindya Chatterjee


System.Data.SQLite does not provide CreateDatabase() and DeleteDataase() dynamic database creation at the moment. At least, this forum post is unanswered for approximately a month.
We already offer both dynamic database creation and CTP 5 support, and plan to blog about CTP 5 support in dotConnect for SQLite soon.
UPDATE. The CTP 5 article is available. It contains some notes concerning database creation peculiarities, and a sample illustrating CTP 5 usage.

like image 24
Devart Avatar answered Sep 28 '22 01:09

Devart