Room多表查询不能嵌套
Posted endian11
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Room多表查询不能嵌套相关的知识,希望对你有一定的参考价值。
WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().getFailedProjects().observe(TrainFragment.this, new Observer<List<FailedProj_select>>() { @Override public void onChanged(List<FailedProj_select> failedProj_selects) { for (FailedProj_select f : failedProj_selects) { item_id += f.getScore_deducting(); Log.i(TAG, "onChanged: "+f.toString()); Toast.makeText(getActivity().getApplicationContext(),"得分"+item_id,Toast.LENGTH_SHORT).show(); } } });
像这种的会重复查多次
正确的写法如下:两段代码平行分开不能嵌套
WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().getSubject(1).observe(this, new Observer<Integer>() { @Override public void onChanged(Integer integers) { Log.i(TAG, "onChanged: "+integers.intValue()); item_id = 0; } }); WorkRoomDataBase.getWorkRoomDataBase(getContext().getApplicationContext()).getFailProjDao().getFailedProjects().observe(TrainFragment.this, new Observer<List<FailedProj_select>>() { @Override public void onChanged(List<FailedProj_select> failedProj_selects) { for (FailedProj_select f : failedProj_selects) { item_id += f.getScore_deducting(); Log.i(TAG, "onChanged: "+f.toString()); Toast.makeText(getActivity().getApplicationContext(),"得分"+item_id,Toast.LENGTH_SHORT).show(); } } });
以上是关于Room多表查询不能嵌套的主要内容,如果未能解决你的问题,请参考以下文章
MySQL 基础 -- 多表关系(一对一1对多(多对一)多对多)多表查询(内连接外连接自连接子查询(嵌套查询)联合查询 union)笛卡儿积