Windows RT上的关系SQLite [英] Relational SQLite on Windows RT

查看:159
本文介绍了Windows RT上的关系SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 SQLite for Windows Runtime ,但我没有看任何方式来定义表之间的关系。 SQLite for WinRT支持该功能吗?

如果不是的话,是否有任何其他解决方案为Windows RT的关系本地数据库?解决方案 / div>

数据库引擎本身支持关系。一种方法是在创建表时指定外键:

  CREATE TABLE Foo(
Id整数主键自动增量不为空,
...


CREATE TABLE Bar(
Id整数主键自动增量不为空,
FooId整数不为空REFERENCES Foo Id)ON UPDATE CASCADE,
...

db连接必须通过执行下面的编译指示来启用外键:

  PRAGMA foreign_keys = ON 

就可用的ORM而言,我想这取决于。我只使用 SQLite-Net ,所以我只能说这个。据我所知,外键目前不是SQL-Net支持的功能。您必须手动管理关系。例如,假设你的 Foo 对象有一个引用到 Bar object。



创建表时,不能使用SQLite-Net表创建方法。您必须使用SQL来创建表和关系。



此外,当您使用SQL-Net加载 Foo 对象,相关的 Bar 对象不会自动加载。您将需要进行第二次SQL-Net调用来加载 Bar 对象。


i am using SQLite for Windows Runtime but i dont see any way to define relationships between tables. Is this feature supported in SQLite for WinRT?

If not, are there any alternative solutions for relational local database for Windows RT?

解决方案

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.

这篇关于Windows RT上的关系SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆