ef4 cause Circular reference in web service

前端 未结 3 1165
庸人自扰
庸人自扰 2020-11-29 10:54

I have a Reason object:

public class Reason
{
    public virtual long Id { get; set; }
    public virtual string Name { get; set; }
    public virtual Comp         


        
3条回答
  •  情话喂你
    2020-11-29 11:26

    You haven't supplied the definition for your company class.... But I'm guessing you have a collection of Reason as a property.

    Lazy loading in an SOA Enviroment doesn't really work. You can't have unlimited lazy navigation over a serialized class, once you leave the webmethod you have no way to call back into the original datacontext from the webmethod consumer to lookup the properites... so the serializer will try and visit all properties, including lazy properties at the time of serialization.

    You need to disable serialization on one part of the circular reference, either on the Reason collection in Company class, or the Company in Reason class.

    You can use the "NotSerialized" attribute to disable serialization of a particular field.

提交回复
热议问题