且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows RT上的关系SQLite

更新时间:2023-02-17 13:16:29

The database engine itself supports relationships. One way is to specify the foreign keys when creating the tables:

CREATE TABLE Foo(
Id integer primary key autoincrement not null ,
...
)

CREATE TABLE Bar(
Id integer primary key autoincrement not null,
FooId integer not null REFERENCES Foo (Id) ON UPDATE CASCADE,
...
)

I believe each db connection has to also enable foreign keys by executing the following pragma:

PRAGMA foreign_keys = ON

In terms of the available ORMs, I guess that depends. I have only used SQLite-Net, so I can only speak about that. As far as I know, foreign keys are currently not a supported feature for SQL-Net. You have to manually manage the relationships.

For example, lets say your Foo object has a reference in it to a Bar object.

For creating the tables, you cannot use the SQLite-Net table creation methods. You have to use SQL to create the tables along with the relationships.

Also, when you use SQL-Net to load the Foo object, the related Bar object will not automatically be loaded. You will need to make a second SQL-Net call to load the Bar object.