JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles. Path: $.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.Id.
public class AppDbContext: DbContext
{
public AppDbContext(DbContextOptions options) : base(options)
{
}
public DbSet Doctors { get; set; }
public DbSet Specialities { get; set; }
}
public class Doctor
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public int SpecialityId { get; set; }
public Speciality speciality { get; set; }
}
public class Speciality
{
public int SpecialityId { get; set; }
public string SpecialityName { get; set; }
public ICollection Doctor { get; set; }
}
Я попробовал использовать Async и сначала ждал, и он выдал ту же ошибку.
Я установил Microsoft.AspNetCore.Mvc.NewtonsoftJson и все равно получаю эту ошибку.
Я получаю эту ошибку при попытке запросить этот контроллер Сообщение об ошибке [code]JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles. Path: $.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.speciality.Doctor.Id.[/code] Контроллер [code] public IActionResult List(int id) { var doc = _context.Doctors.Include(t => t.speciality).ToList(); return Json(doc); } [/code] Вот контекст данных и модели [code] public class AppDbContext: DbContext { public AppDbContext(DbContextOptions options) : base(options) {
} public DbSet Doctors { get; set; } public DbSet Specialities { get; set; }
}
public class Doctor { public int Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; }
public int SpecialityId { get; set; } public Speciality speciality { get; set; }
}
public class Speciality { public int SpecialityId { get; set; } public string SpecialityName { get; set; }
public ICollection Doctor { get; set; } } [/code] Я попробовал использовать Async и сначала ждал, и он выдал ту же ошибку. Я установил Microsoft.AspNetCore.Mvc.NewtonsoftJson и все равно получаю эту ошибку.