How to stop self-referencing loop in .Net Core Web API?

后端 未结 3 1116
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 21:00

I\'m having some issues which I\'m guessing are related to self-referencing using .NET Core Web API and Entity Framework Core. My Web API starting choking when I added .Inc

3条回答
  •  孤街浪徒
    2020-12-03 21:27

    Okay... I finally found some reference material on this. The solution is:

    public void ConfigureServices(IServiceCollection services)
    {
        ...
    
        services.AddMvc()
            .AddJsonOptions(
                options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            );
    
        ...
    }
    

    I got this from here

提交回复
热议问题