开发者

Import exisiting data into CoreData

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开发者_JS百科 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜