I have a Reason object:
public class Reason { public virtual long Id { get; set; } public virtual string Name { get; set; } public virtual Company Company {get;set;} }
I use the framework 4 entity, and the company is a navigation property for the Company.
I also use webservices to return data to the client.
I have a web method that returns the reasons:
[WebMethod] public Reason[] GetCallReasons() { IReasonRepository rep = ObjectFactory.GetInstance<IReasonRepository>(); return rep.GetReasonsList().ToArray(); }
Due to ef4, I get the following exception for executing the web method:
A circular reference was detected while serializing an object of type 'System.Data.Entity.DynamicProxies.Reason_24A0E4BBE02EE6BC2CF30BB56CFCB670C7D9D96D03D40AF4D174B89C9D3C5537'
The problem is that ef4 adds a property that cannot be serialized: 
To solve this problem and fix the error, I can turn off the navigation property without making it virtual or deleting the navigation property. But I understand it and want to use the lazy boot function.
I can also write a special serializer for Reason, but I have many classes that I used in my web services, and writing a serializer for all of them is a lot of work.
How can I resolve this exception? ..
source share