【发布时间】:2021-04-29 08:19:19
【问题描述】:
我有一个包含 id 和 code 的数据类。
我有一个只包含代码的列表。
如何在不补id的情况下将代码插入表格?
其实我根本不需要 id 列,但是好像 Room 需要主键,code 不能是主键。
房间:
@Entity(tableName = "raw_table")
data class Raw(
@PrimaryKey(autoGenerate = true)
var id: Long = 0L,
@ColumnInfo(name = "code")
var code: String = "",
...
列表和循环:
val codeList : List<String> = ...
for (code in codeList){
// wrong here, I need the id, but I do not have ids.
RawDao.insert(code)
}
【问题讨论】:
标签: android insert android-room primary-key dao