Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 实体框架Include具有无限引用_C#_.net_.net Core_Entity Framework Core - Fatal编程技术网

C# 实体框架Include具有无限引用

C# 实体框架Include具有无限引用,c#,.net,.net-core,entity-framework-core,C#,.net,.net Core,Entity Framework Core,我已经回顾了entity framework Include()的许多解决方案,但找不到有效的解决方案。当我使用context.A.Include(x=>x.B)时;它包含父对象和子对象的无限引用。我想禁用这个。换句话说,A->B和B->A和A->B等等。这会导致超时和性能问题。我如何避免这种情况?使用.NET Core 3.1。您需要它进行序列化吗?我正在使用MVC设置检索表及其所有外键引用,以便在站点中进行用户管理。但是从API返回的数据应该只有父对象和子对象。并非所有其他父/子引用都被无限

我已经回顾了entity framework Include()的许多解决方案,但找不到有效的解决方案。当我使用context.A.Include(x=>x.B)时;它包含父对象和子对象的无限引用。我想禁用这个。换句话说,A->B和B->A和A->B等等。这会导致超时和性能问题。我如何避免这种情况?使用.NET Core 3.1。

您需要它进行序列化吗?我正在使用MVC设置检索表及其所有外键引用,以便在站点中进行用户管理。但是从API返回的数据应该只有父对象和子对象。并非所有其他父/子引用都被无限嵌套。请选中此复选框。有人应该向您发送$$$$。谢谢♥仅供其他人参考:包-Microsoft.AspNetCore.Mvc.NewtonsoftJson Dotnet version-3.1 Startup-services.AddMvc().AddNewtonsoftJson中的代码(options=>options.SerializerSettings.ReferenceLoopHandling=ReferenceLoopHandling.Ignore);
public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc()
        .AddJsonOptions(
            options => options.SerializerSettings.ReferenceLoopHandling = 
              Newtonsoft.Json.ReferenceLoopHandling.Ignore
        );
}