EF:CF多对多的分离语境 [英] EF:CF Many-To-Many in a Detached Context
问题描述
书
对象和三个类别
对象,其中之一由两个书
对象,通过序列化类 c> c c>
两次?分别序列化我的 Book
对象和类别
对象,并重新建立关系后序列化是有益的。 我想这可能取决于序列化程序。如果任何人有任何其他有关最佳方法的提示,我将不胜感激。
您需要使用使用引用跟踪进行序列化(如果您从将导航属性从
到
类别
和类别
到书
否则你会收到循环引用异常)。一旦你使用这个序列化,每个实体将被序列化一次。
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.
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.
这篇关于EF:CF多对多的分离语境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!