I have just found @PrimaryKey annotation in room. So If I want to make composite key so how can I make that in MVVM ?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Make use of primaryKeys()
.
Android Developer Documentation for Room
states:
If PrimaryKey annotation is used on a Embeddedd field, all columns inherited from that embedded field becomes the composite primary key (including its grand children fields).
Example implementation:
@Entity(primaryKeys = {"column1","column2","column3"})
class DummyClass {
...
}
Thanks Lalit Kushwah for the example.
回答2:
Here is an example
import android.arch.persistence.room.Entity
@Entity(primaryKeys= [ "first_name", "last_name" ] )
class User{
.......
}