EF:CF多对多的分离语境 [英] EF:CF Many-To-Many in a Detached Context

查看:140
本文介绍了EF:CF多对多的分离语境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个对象有很多关系,我们把它们称为Book和Category。实体框架中的标准做法 - 代码优先是将它们映射到一起,并将导航属性放在任一方面,我已经完成了。我在一个独立的环境中工作,所以我需要序列化我的对象。所以如果我有两个对象和三个类别对象,其中之一由两个对象,通过序列化类 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆