核心数据对多关系。它们是延迟负载吗? [英] Core Data to-many relationships. Are they Lazy Load?

查看:136
本文介绍了核心数据对多关系。它们是延迟负载吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个典型的模型在核心数据(iPhone)与部门和雇员(部门 - >>员工)。



我不想加载所有员工一个部门,每次我加载它,所以我想我会创建Employee作为获取属性。我想我可以这样定义一些谓词:

  employee.deparmentId = department.departmentId 



但我不能(使用Xcode图形编辑器)。





我的问题是:是多对多关系Lazy正在加载?或者每次我创建(检索)部门列表时,是否会在数据库中加载我的所有员工?



感谢提前
Gonso

解决方案

否,与多对和一对一关系相关的对象默认是长时间加载的。但是,如果您需要在每次获取部门时访问其中许多部门,那么出于性能原因,您可能会要求Core Data同时加载它们(这称为预取)。您可以执行以下操作:

  [fetchRequest setReturnsObjectsAsFaults:NO]; 
[fetchRequest setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@employees,nil]];


I have the typical model in Core Data (for iPhone) with Departments and Employesss (Department ->> Employee).

I dont want to load all employees of a department each time I load it, so I thought I'd create the Employee as a Fetched Property. I thought I could define some Predicate like this:

employee.deparmentId = department.departmentId

but I couldn't (with Xcode graphic editor).

Now, reading some posts, Im inclined to define a relationship to-many for Department to Employee (and its reverse) and use it.

My question is: Are to-many relationship Lazy Loading? or is it going to load all my Employees in the "database" each time I create (retrieve) a list of departments?

Thanks in advance Gonso

解决方案

No, objects related to to-many and to-one relationships are loaded lazily by default. However, If you need to access many of them each time you fetch a Department, then for performance reasons you may ask Core Data to load them simultaneously (this is called pre-fetching). You can do this as follow:

[fetchRequest setReturnsObjectsAsFaults:NO];
[fetchRequest setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"employees", nil]];

这篇关于核心数据对多关系。它们是延迟负载吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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