When I call
_dbContext.Employees
.Include(e => e.Company)
.Where(e => e.IsDelete == false)
I get model Employee
with a Company
inside, which contains an Employee
, and that has a Company
and so on - endlessly
This causes an error:
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: $.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee.Company.Employee
Solution with JsonConvert
works, but it's not suitable
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
it is advisable to solve this issue on the EF side