Two in one. In today post we will talk about two different topics:
This days we had to update an application with the latest and greatest version of Entity Framework and SQLite. After a few hours of working we manage to update SQLite and EF to the new version and we manage to make the application to compile and start.
Now was the moment of true, to check if the unit tests are still green. And surprise, some of them are red, even if the application seems to run without any kind of problem. It seems that in the new version of EF or SQLite the behavior or functionality of a specific feature was changed.
Odd behavior of SQLite and Entity Framework
Before the update:
With the latest version of EF (6.1) in combination with SQLite NuGet Package (1.0.94) we had a big surprise. The cascade deletion was not triggered anymore by the above command. We were lucky with unit tests that cached this problem immediately after update.
The final solution was pretty “special”. Move the PRAGMA command from the command query to the connection string.
Connection string:
In conclusion we learn that unit tests can be useful to catch odd behavior, even the one related to frameworks updates. Also, it seems that from time to time the behavior of canonical commands can change.
- An example from real life that shows why unit tests are important
- An odd behavior of SQLite combined with Entity Framework
This days we had to update an application with the latest and greatest version of Entity Framework and SQLite. After a few hours of working we manage to update SQLite and EF to the new version and we manage to make the application to compile and start.
Now was the moment of true, to check if the unit tests are still green. And surprise, some of them are red, even if the application seems to run without any kind of problem. It seems that in the new version of EF or SQLite the behavior or functionality of a specific feature was changed.
Odd behavior of SQLite and Entity Framework
Before the update:
PRAGMA foreign_keys = ON;
DELETE FROM CarsHistory
WHERE (julianday(datetime('now'))-julianday(CarBuyDate))>360
Executed as a SQL command from Entity Framework used to trigger also the delete cascade in the tables around CarsHistory. This was the expected behavior, taking into account that delete cascade feature was activated for that tables.With the latest version of EF (6.1) in combination with SQLite NuGet Package (1.0.94) we had a big surprise. The cascade deletion was not triggered anymore by the above command. We were lucky with unit tests that cached this problem immediately after update.
The final solution was pretty “special”. Move the PRAGMA command from the command query to the connection string.
Connection string:
data source=C:\Dbs\myCardDb.db;foreign keys=true;
Command:DELETE FROM CarsHistory
WHERE (julianday(datetime('now'))-julianday(CarBuyDate))>360
It seems that the old method to trigger a cascade delete is not anymore supported.In conclusion we learn that unit tests can be useful to catch odd behavior, even the one related to frameworks updates. Also, it seems that from time to time the behavior of canonical commands can change.
How we can integrate SQLite with EF into a .Net Application?
ReplyDeleteI think that this link would be useful for you http://bricelam.net/2012/10/entity-framework-on-sqlite.html
Delete