Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a simple sqlite database with two tables. When I manually delete (using SQLite Expert)an entry in table DataSets, the coresponding entry in OneD is deleted as expected. When I delete an entry in DataSets from Entity Framework it does not cause the coresponsing entry in One D to be deleted. There is no error generated.

Any idea why?

Regards

Here is the database definition:

CREATE TABLE [DataSets] (
  [DataSetId] INTEGER NOT NULL ON CONFLICT FAIL PRIMARY KEY AUTOINCREMENT, 
  [Description] TEXT(128));

CREATE TABLE [OneD] (
  [OneDId] INTEGER NOT NULL ON CONFLICT FAIL PRIMARY KEY ON CONFLICT ABORT AUTOINCREMENT, 
  [DataSetId] INTEGER NOT NULL ON CONFLICT FAIL UNIQUE ON CONFLICT ABORT REFERENCES [DataSets]([DataSetId]) ON DELETE CASCADE, 
  [StockSheetLength] INTEGER NOT NULL ON CONFLICT FAIL);

Here is how I delete the entry from EF

        var dataSets = from ds in context.DataSets select ds;
        foreach (var ds in dataSets)
            context.DataSets.DeleteObject(ds);

        context.SaveChanges();
        return true;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
380 views
Welcome To Ask or Share your Answers For Others

1 Answer

The problem can be solved by enabling foreign keys in the connection string:

data source=mydb.db;foreign keys=true

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...