Entity framework EF核心一对多无限包含

Entity framework EF核心一对多无限包含,entity-framework,.net-core,ef-fluent-api,Entity Framework,.net Core,Ef Fluent Api,我有两个表预约和任务分配有一对多的关系。现在当我得到约会的时候 public IEnumerable<Appointment> GetAppointments(int employeeId, DateTime date) { return _context.Appointment.Where(a => a.EmployeeId == employeeId && a.AppointmentDate == date)

我有两个表预约和任务分配有一对多的关系。现在当我得到约会的时候

public IEnumerable<Appointment> GetAppointments(int employeeId, DateTime date)
    {
        return _context.Appointment.Where(a => a.EmployeeId == employeeId && 
            a.AppointmentDate == date)
           .Include(a=>a.Tasks).ToList();
    }
public IEnumerable getAppointment(int-employeeId,DateTime-date)
{
return\u context.Appointment.Where(a=>a.EmployeeId==EmployeeId&&
a、 任命日期==日期)
.Include(a=>a.Tasks).ToList();
}

它会导致包括一个具有多个任务的约会,以及一个具有多个任务的约会的任务等等。

在ConfigureService中,您需要添加Json选项来处理引用循环处理

.AddJsonOptions(options =>
{
    options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize;
    options.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects;
});
或者,您可以选择通过以下方式直接忽略引用循环:

options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;

我也有同样的问题,通过查看输出,我注意到在最初调用获取数据之后没有调用加载数据。