将现有数据导入 CoreData
我有一个现有的数据库(SQL Server),其中有几个使用主/外键关系连接的表。该数据库包含数据并用于填充网站。
我现在想在使用 CoreData 的 Mac/iOS 应用程序中使用这些数据,并创建了 Apple(以及网上许多其他人)指定的数据模型和关系。我有一个简单的服务,可以从远程系统中提取数据,但现在正在努力了解如何使用我的 CoreData 模型将该数据保留在设备上。
由于 CoreData 是一个对象图而不是数据库,我不知道如何保留主/外键关系,因为这是从开发人员那里抽象出来的 CoreData 实现细节。我的远程系统中的数据依赖于这些已经形成的关系才能正常运行。
有没有人知道如何解决这个问题或者以前遇到过这个问题?或者我是从错误的角度来看这个问题的?
无论哪种方式,我都需要某种方法将远程数据复制到 Mac/iOS 设备上。
非常感谢。
I have an existing database (SQL Server) which has several tables connected using primary/foreign key relationships. The database contains data and is used to populate a website.
I now want to use this data within a Mac/iOS application using CoreData and have created a data model and relationships as specified by Apple (and many others out there on the net). I have a simple service that pulls down the data from the remote system but am now struggling to see how I can use my CoreData model to persist this data on the device.
As CoreData is an object graph and not a database I do not know how I can preserve my primary/foreign key relationships as this is a CoreData implementation detail abstracted away from the developer. The data I have in my remote system relies on these already formed relationships to function correctly.
Does anybody out there know how to solve this issue or has come across it before? Or am I coming at this from the wrong angle?
Either way I need some way of replicating my remote data onto a Mac/iOS device.
Many thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
外键是核心数据中的关系。要传输数据库,您需要通读每一行并在核心数据中创建一个新实体。要重新创建关系,您也可以将旧的 id 数据存储在其中,然后查询核心数据以查找具有该 id 的实体,并创建关系。如果您只需要传输一次,则可以在导入完成后删除 ids。
Foreign keys are relationships in Core Data. To transfer your database, you'll need to read through each row and make a new entity in Core Data. To recreate the relationships, you could store the old id data in there too, then query Core Data for an entity with that id, and create the relationship. If you only need to transfer it one time, you can delete the ids when the import is done.