房间数据库获取类型集

问题描述 投票:0回答:2

我需要从set中获取字符串RoomDatabase

实体:

@Entity
data class Data(
@PrimaryKey val id: Int,
val type: String,
val photo: String
)

我需要获取类型的set。我尝试遵循方法:

...
@Query("SELECT type FROM data")
fun getAllTypes(): LiveData<Set<String>>
...

现在我有下一个错误:

C:\...\storage\DataDao.java:24: error: Not sure how to convert a Cursor to this method's return type (androidx.lifecycle.LiveData<java.util.Set<java.lang.String>>).
    public abstract androidx.lifecycle.LiveData<java.util.Set<java.lang.String>> getAllTypes();
[WARN] Incremental annotation processing requested, but support is disabled because the following processors are not incremental: androidx.room.RoomProcessor (DYNAMIC).

> Task :app:kaptDebugKotlin FAILED
android kotlin android-room androidx
2个回答
1
投票

抱歉,您无法获得Set。根据SELECT查询的文档,您只能使用列表或数组。

https://developer.android.com/reference/androidx/room/Query

如果需要独特的物品,可以使用SQL的DISTINCT。


0
投票

也许是这样:

@Query("SELECT type FROM data")

必须是:

@Query("SELECT type FROM Data")
© www.soinside.com 2019 - 2024. All rights reserved.