EF4:仅序列化 Poco 对象的预加载导航属性
我正在使用返回 POCO 对象的 WCF 服务。我的导航属性被标记为虚拟以启用延迟加载/代理。我还使用 [ApplyDataContractResolver] 模式将代理序列化为父 POCO 对象。一切正常,直到我将导航属性添加到关系的两侧,这会导致循环引用 - 导致它无法正确序列化。有什么方法可以告诉序列化器仅序列化急切加载的(使用 .include())导航属性并忽略尚未加载的导航属性而不是填充它们?
I am using a WCF Service which returns POCO objects. My navigation properties are marked as virtual to enable lazy loading/proxies. I also use the [ApplyDataContractResolver] pattern to serialize the proxies as the parent POCO object. Everything works fine until I add navigation properties to both sides of a relationship, which causes a circular reference - causing it to not serialize properly. Is there any way to tell the serializer to serialize only the eager loaded (using .include()) navigation properties and ignore the navigation properties that aren't loaded yet instead of populating them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除非您手动定义< /a>.此外,它不会对您有帮助,因为您仍然可以通过循环引用急切加载实体。如果你想通过 WCF 发送 POCO,你应该关闭延迟加载,因为你永远不会避免延迟加载不必要的属性,除非你永久地将所有这些属性从属性的序列化中排除,但在这种情况下,它们在急切加载后也不会被序列化。
Serializing only eager loaded properties is not possible unless you manually define that. Moreover it will not help you because still you can have eager loaded entities with circular reference. If you want to send POCO over WCF you should turn off lazy loading because you will never avoid lazy loading unnecessary properties unless you permanently exclude all of them from serialization by attributes but in such case they will not be serialized after eager loading as well.