Guys I have a One to many relation to same class called user,
I am returning one instance of user in web apis get method
it works fine as far as I don\'t have any
Try to change webApi formatter. Add these lines in WebApiConfig.cs:
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);
And add this line:
json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
Apply the
[JsonIgnore]
attribute to the navigation property you don't want to be serialised. It will still serialise both the parent and child entities but just avoids the self referencing loop.