【问题标题】:ObjectBox - select only some columnsObjectBox - 只选择一些列
【发布时间】:2020-06-15 18:58:45
【问题描述】:

假设我有一个像这样的 ObjectBox 实体:

@Entity
public class CountryEntity {

    @Id
    private long entityId;

    private String name;
    private float area;
    private int population;
    private String subRegion;
    private String region;
    private String code3;
    private String capitalCity;

    setters, getters }


还有一个查询:

public ObjectBoxLiveData<CountryEntity> getAllCountries(){
       Box<CountryEntity> countryBox = boxStore.boxFor(CountryEntity.class);
       return new ObjectBoxLiveData<CountryEntity>(
               countryBox.query().order(CountryEntity_.name).build());
   }

这会选择所有国家/地区。有没有办法只选择一些“列”,例如。 name 和 area 例如而不是其他?

通常我并不真正需要所有列,而是需要一个子集,而且我对不必要地查询所有这些数据感到非常内疚。

谢谢!

【问题讨论】:

    标签: java android objectbox


    【解决方案1】:

    不要太担心。 ObjectBox 创建对象的速度非常快(可能比其他解决方案快 10 倍)。所以除非你携带例如大型二进制对象应该没问题。

    查询单个属性,你可能见过property queries。

    否则,您可能想要投票支持此功能请求: https://github.com/objectbox/objectbox-java/issues/348

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-17
      • 2015-05-04
      • 1970-01-01
      • 2021-08-20
      相关资源
      最近更新 更多