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 work开发者_如何学运维s 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?
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.
精彩评论