How to do a room query using a instance of a class as a data source: The following example will make my question clear:
@Query("UPDATE CATEGORIES SET Name = :item.Name, Active = :item.Active " +
"WHERE CategoryID = :item.CategoryID")
fun updateCategory(item: EntityCategory)
I tried
@Update
fun updateCategory(item: EntityCategory)
But that would delete all refrencing data
My Entity class:
@Entity(tableName = "CATEGORIES")
data class EntityCategory(
@PrimaryKey(autoGenerate = false)
var CategoryID: Long,
var Name: String,
var Active: Boolean) {
constructor(item: DMCategory) : this(item.CategoryID, item.Name, item.Active)
}
I cant have my Primary key auto generated.
Yes, you can pass query parameters from some object.
Try
@Insert(onConflict = OnConflictStrategy.REPLACE)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With