问题描述
我想实现Android Room持久性。 这是我的DAO界面。
@Dao
interface FoodDao {
/**
* Returns all data in table for Paging
*
* @param query a dynamic SQL query
*/
@RawQuery
fun getAll(query: SupportSQLiteQuery): DataSource.Factory<Int,Food>
}
由于某种原因,我有此编译错误:
错误:可观察到的查询返回类型(LiveData,Flowable,DataSource,DataSourceFactory等)只能与直接或间接(例如,通过@Relation)访问至少一个表的SELECT查询一起使用。对于@RawQuery,应通过observedEntities字段指定要观察的表的列表。 公共抽象androidx.paging.DataSource.Factory解决方法
您必须指定观察到的实体:
@RawQuery(observedEntities = [Food :: class])
查看更多信息:https://developer.android.com/reference/android/arch/persistence/room/RawQuery