Serialize one to many relationships in Json.net

后端 未结 5 547
盖世英雄少女心
盖世英雄少女心 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 08:53

    If you're using WebAPI EntityFrameworkCore 2.0 this solution doesn't work, you need to set it on Startup.cs->ConfigureServices:

    .AddJsonOptions(options => {
                        var settings = options.SerializerSettings;
                        settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                    });
    

提交回复
热议问题