EF4:仅序列化 Poco 对象的预加载导航属性

发布于 2024-11-08 06:45:23 字数 211 浏览 0 评论 0原文

我正在使用返回 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多孤肩上扛 2024-11-15 06:45:23

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文