问题
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