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>
This database provider allows Entity Framework Core to be used with SQLite. The provider is maintained as part of the Entity Framework Core project.
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.
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.
It seems to me that current SQLite.net does not support Entity Framework CTP5 code first. Will have to wait for that to happen.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With