How to fill non column field of entity in room library

前端 未结 4 1379
天命终不由人
天命终不由人 2021-02-01 21:00

I have a class entity as below

@Entity
public class Task {    
    private String name; 
    private Integer ParentId;
    private Integer userId;   
    @Ignore         


        
4条回答
  •  离开以前
    2021-02-01 21:30

    Create a sub class of Task suppose

    public class TaskDisplayModel extends Task{
    
    @Ignore
    private transient int noOfSubTask;
    
    }
    

    Then your query will be

    @Query("SELECT *,(SELECT count(*) FROM Task b  WHERE a._id = b.ParentId ) AS noOfSubTask FROM Task a ")
    LiveData> getTaskList();
    

提交回复
热议问题