Entity Framework core .Include() issue

后端 未结 4 1079
长发绾君心
长发绾君心 2021-02-18 22:05

Been having a play about with ef core and been having an issue with the include statement. For this code I get 2 companies which is what i expected.



        
4条回答
  •  孤独总比滥情好
    2021-02-18 22:43

    I'm not sure if you've seen the accepted answer to this question, but the problem is to do with how the JSON Serializer deals with circular references. Full details and links to more references can be found at the above link, and I'd suggest digging into those, but in short, adding the following to startup.cs will configure the serializer to ignore circular references:

    services.AddMvc()
        .AddJsonOptions(options => {
            options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
        });
    

提交回复
热议问题