实体与实体之间的关系_房间中的实体关系

实体与实体之间的关系

Note: This article is part of the advanced Room series which covers all the details about the Room persistence library. You can read all the articles here:

注意:本文是高级Room系列的一部分,该系列涵盖有关Room持久性库的所有详细信息。 您可以在此处阅读所有文章:

房间中的实体关系 (Entity Relationships in Room)

This article covers how we can define relationship between entities in Room persistence library.

本文介绍了如何在Room Persistence库中定义实体之间的关系。

Since SQLite is a relational database, entities can have relationships between them. In Room, entities cannot directly reference other entities because it might cause loading unnecessary data every time.

由于SQLite是一个关系数据库,因此实体之间可以具有关系。 在Room中,实体无法直接引用其他实体,因为这可能会导致每次加载不必要的数据。

Still sometimes, you would want to reference other entities from your entity. You can acheive this in multiple ways.

有时,您仍想从您的实体中引用其他实体。 您可以通过多种方式来实现。

嵌入式对象 (Embedded Objects)

You can use the @Embedded annotation to represent an object that you'd like to decompose into its subfields within a table(entity). You can then query the embedded fields just as you would for other individual columns.

您可以使用@Embedded批注表示要分解为表(实体)内其子字段的对象。 然后,您可以查询嵌入字段,就像查询其他各个

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值