在Room Persistence Library中使任何列自动生成(不是主键) [英] Make any column autoGenerate (Not Primary Key) in Room Persistence Library

查看:179
本文介绍了在Room Persistence Library中使任何列自动生成(不是主键)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要自动生成

ID//自动,但不是主要

ID // auto but not primary

列并设置

productID//主要不是自动

productID // primary not auto

作为主键... 有可能还是我的想法错了...? 如果我的想法是错误的,那么请给我写信... 谢谢

as the primary key... Is it possible or my idea is wrong...? if my idea is wrong then please give me the write info... thanks

//@PrimaryKey(autoGenerate = true)
@Nullable  // I want to autogenerate this "ID" column 
private long ID;

@ColumnInfo(name = "pCategorySubID")
@SerializedName("pCategorySubID")
@Expose
private String pCategorySubID;

@PrimaryKey // this is my primary key
@ColumnInfo(name = "ProductID")
@SerializedName("ProductID")
@Expose
@NonNull
private String productID;

推荐答案

您可以使用

You can use index parameter from column info tag:

例如@ColumnInfo(index = true)

ex. @ColumnInfo(index = true)

//@PrimaryKey(autoGenerate = true)
@ColumnInfo(index = true) // use this to make it index
@Nullable  // I want to autogenerate this "ID" column 
private long ID;

@ColumnInfo(name = "pCategorySubID")
@SerializedName("pCategorySubID")
@Expose
private String pCategorySubID;

@PrimaryKey // this is my primary key
@ColumnInfo(name = "ProductID")
@SerializedName("ProductID")
@Expose
@NonNull
private String productID;

这篇关于在Room Persistence Library中使任何列自动生成(不是主键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆