Сообщение об ошибке
Код: Выделить всё
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 IActionResult List(int id)
{
var doc = _context.Doctors.Include(t => t.speciality).ToList();
return Json(doc);
}
Код: Выделить всё
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; }
}
Я установил Microsoft.AspNetCore.Mvc.NewtonsoftJson и все равно получаю эту ошибку.
Подробнее здесь: https://stackoverflow.com/questions/786 ... cted-error