How to make Room Entities
1 min readSep 28, 2020
An entity is, in short, a type that a database table can be or in other words a type of object that a database can hold.
I usually keep my Entities in a Model.kt file inside a model package
@Entity
data class Recipe(
@PrimaryKey
@ColumnInfo("recipename")
val recipeName: String
)@Entity
data class Ingredient(
@PrimaryKey
@ColumnInfo("ingredientName")
val ingredientName: String
)
The code above shows a very simple data class named Recipe that holds a name value for recipe (recipeName) of type String, and another data class named Ingredient which holds a name value for an ingredient (ingredientName) also of type String.
For this article I decided to have very simple data classes but know that your classes can hold more variables if you want them to.