android - "WHERE IN"使用 greendao Android ORM 的语句

标签 android sqlite orm greendao

我正在使用 greendao 在我的应用程序中使用 sqlite 数据库。
我需要具有 where in 条件
这样的功能 我正在寻找这样的方法或任何其他可能的方法,但不使用原始查询。

我需要执行此类查询SELECT * FROM news WHERE id_company IN (SELECT id FROM company WHERE state=1

请建议使用 GreenDAO ORM 执行此类查询的最佳方式是什么。

最佳答案

您可以使用Lists.transform()来自 Guava ,如此处所述 link

List<Company> companies = session.getCompanyDao()
                           .queryBuilder()
                           .where(CompanyDao.properties.state.eq(1))
                           .list();

Function<Company, Integer> companyToId = new Function<Company,Integer>() { 
    public String apply(Company c) { return c.getId(); }
};

List<Integer> ids = Lists.transform(companies, compnayToId);


session.getNewsDao()
.queryBuilder()
.where(NewsDao.Properties.id_company.in(ids))
.list();

关于android - "WHERE IN"使用 greendao Android ORM 的语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34555831/

相关文章:

android - 设置onclicklistener时应用程序崩溃

hibernate - 将 JPA 实体命名为 "Group"是否非法?

database - 什么是适合我使用 Kotlin 的需求的轻量级 ORM?

orm - Doctrine 2 OneToOne 实体映射返回空实体

android - 从字符串类型变量解析json

Android Listview 图片大小

android - 如何借助广播接收器检测来电?

sqlite - Windows 上的 "Failed at the sqlite3@3.1.13 install script ' node-pre-gyp install --fallback-to-build '"

mysql - 为什么我的 Rails 函数在 SQLite 中有效,但在 MySQL 中无效?

android - SQLiteDatabase.execSQL() 不工作。它给我消息 "Non-static method ' execSQL' cannot be a reference from a static context"