Serialize one to many relationships in Json.net

后端 未结 5 565
盖世英雄少女心
盖世英雄少女心 2020-12-08 08:44

I am using the Entity Framework code first for data access and I have a Company class which has a collection of Employees. The Employee class also has a Company property.

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-08 09:16

    If you are getting this error using WebApi you can put the following in WebApiConfig.cs so json.net ignores circular refs

    config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; 
    

    Microsoft : Loop Reference handling in Web API

提交回复
热议问题