EF:CF Many-To-Many in a Detached Context

老子叫甜甜 提交于 2019-12-11 11:48:06

问题


I have two objects with a many to many relationship, let's call them Book and Category. The standard thing to do in Entity Framework - Code First would be to map them together and put a navigation property on either side, which I have done. I am working in a detached context, so I need to serialize my objects. So if I have two Book objects and three Category objects, one of which is shared by the two Book objects, do I suffer a performance loss by serializing the Book objects as they are by serializing the shared Category twice? Would it be beneficial performance-wise to serialize my Book objects and Category objects separately and rebuild the relationship post-serialization?

I suppose it might depend on the serializer. If anyone has any other tips on the best method to go about this, I would appreciate any advice.


回答1:


You need to use serialization with reference tracking (you must do it anyway if you have navigation properties from Book to Category and from Category to Book otherwise you will get circular reference exception). Once you use this serialization each your entity will be serialized only once.



来源:https://stackoverflow.com/questions/9071118/efcf-many-to-many-in-a-detached-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!