是否可以仅提取Core Data查询中的选定属性 [英] Is it possible to fetch only selected property in a Core Data query

查看:166
本文介绍了是否可以仅提取Core Data查询中的选定属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有(我猜)典型的问题。我的核心数据数据库包含表,它们有BLOB字段和相当长的文本字段。

I have (I guess) typical problem. My Core Data database contains table, which have BLOB fields and quite long text fields.

通常我不需要加载这些大字段。由于在数据库中有几千条记录,我更喜欢只获取我真正需要的数据。换句话说,我想要SELECT name,id FROM TAB_NAME查询,而不是SELECT * FROM TAB_NAME查询。

Usually I do not need to load agrresivly those large size fields. Since there are several thousand records in a database I would prefer to fetch only data I truly need. In other words I would like to make "SELECT name, id FROM TAB_NAME" query, not "SELECT * FROM TAB_NAME" query.

有任何方法,字段使用Core Data?或者我应该寻找一些其他选项,例如,将大字段分隔到另一个表?也许有更好的(更简单)的方法来做到这一点?

Is there any way to fetch only selected fields using Core Data? Or shall I look for some other option, like, for instance, seperate large fields to another table? Maybe there is a better (easier) way to do this?

我习惯于使用Hibernate或JPA,它很容易做上述操作,核心数据文档我没有看到这样的选项。

I am used to working with Hibernate or JPA, where it easy to do described above operation, after going through Core Data docs I do not see such option.

推荐答案


换句话说, SELECT name,id FROM TAB_NAMEquery,notSELECT * FROM TAB_NAMEquery。

In other words I would like to make "SELECT name, id FROM TAB_NAME" query, not "SELECT * FROM TAB_NAME" query.

此问题的答案已被接受,但FYI,这里是如何获取一个实体的特定属性与Core Data,而不重新考虑你的模型:

The answer to this question was accepted, but FYI, here's how to fetch only specific properties of an entity with Core Data, without re-factoring your model:

// build your NSFetchRequest
// ...

[request setResultType:NSDictionaryResultType];
[request setPropertiesToFetch:
  [NSArray arrayWithObjects:@"property1", @"property2", /* etc. */ nil]];    

另请参阅NSFetchRequest

这篇关于是否可以仅提取Core Data查询中的选定属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆