Asp.Net Core Web API 2.2 Controller not returning complete JSON

爷,独闯天下 提交于 2019-12-01 17:30:12

I see you are using Eager Loading in your query. So add the following configuration in your Startup class to ignore cycles that it finds in the object graph and to generate JSON response properly.

public void ConfigureServices(IServiceCollection services)
{
    ...

    services.AddMvc()
        .AddJsonOptions(
            options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
        );

    ...
}

For more details: Related data and serialization in EF Core

Try to create and return a DTO or a new struct/class that will not have cyclic info (MessageBoard has Message that has MessageBoard etc...)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!