1

我想使用 Paging 3 Library 以 db 作为 SSO 进行分页,并且我有一些使用嵌入式注释(一对多,关系)示例的数据类↓</p>

  data class PojoEmbended(
    @Embedded
    var messageEntity: MessageEntity,
    @Relation(
        parentColumn = "messageId",
        entityColumn = "messageId",
        entity = AttachmentsEntity::class
    )
    var listAttachments: List<AttachmentsEntity>
)

AttachmentsEntity 长这样↓</p>

@Entity(
    tableName = "ChatAttachments",
    foreignKeys = [ForeignKey(
        entity = MessageEntity::class,
        parentColumns = ["messageId"],
        childColumns = ["messageId"],
        onDelete = ForeignKey.CASCADE
    )],
    primaryKeys = ["messageId"]
)
data class AttachmentsEntity(
    @ColumnInfo(name = "messageId", index = true)
    var messageId: String = "",
    @ColumnInfo(name = "title")
    var title: String = "",
    @ColumnInfo(name = "imageUrl")
    var imageUrl: String = "",
    @ColumnInfo(name = "imageType")
    var imageType: String = ""
)

DAO中的函数↓</p>

 @Transaction
    @Query("SELECT * FROM MessageTable")
    suspend fun getAllChatMessages(): PagingSource<Int, PojoEmbended>

当我尝试制作一个项目时,它失败并出现错误↓</p>

错误:不确定如何将 Cursor 转换为此方法的返回类型 (androidx.paging.PagingSource<"path".PojoEmbended>)。公共抽象 java.lang.Object getAllChatMessages(@org.jetbrains.annotations.NotNull()

问题来了↓
在这种情况下怎么办更好?从 db List 获取我自己的 PagingSource 并在 RemoteMediator 中使用它或删除Embedded注释并使用TypeConverter ?

4

1 回答 1

0

它无法转换为暂停的 PagingSource 返回类型。改为这样做

@Transaction
@Query("SELECT * FROM MessageTable")
fun getAllChatMessages(): PagingSource<Int, PojoEmbended>
于 2021-11-21T16:06:24.667 回答