I tried to serialize POCO class that was automatically generated from Entity Data Model .edmx and when I used
JsonConvert.SerializeObject
To ignore loop references and not to serialize them globally in MVC 6 use the following in startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().Configure(options =>
{
options.OutputFormatters.RemoveTypesOf();
var jsonOutputFormatter = new JsonOutputFormatter();
jsonOutputFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
options.OutputFormatters.Insert(0, jsonOutputFormatter);
});
}