Share via

Cycling problem

Atilla Rüstəmli 60 Reputation points
2024-07-16T19:06:27.2733333+00:00

Hi, I have 2 entity which have one to many relation between. Lets name them School and student. When I'm creating School I'm getting cycling problem . I did all the configuration in Configure class but nothing worked. There is a way with [JsonIgnore] but I don't think it is the best way of it.

Developer technologies | .NET | Entity Framework Core
Developer technologies | ASP.NET | ASP.NET Core
0 comments No comments

2 answers

Sort by: Most helpful
  1. SurferOnWww 5,921 Reputation points
    2024-07-17T00:36:24.5266667+00:00

    There is a way with [JsonIgnore] but I don't think it is the best way of it.

    I understand that the "Cycling problem" means circular references problem due to navigation property and you are looking for other solution than using [JsonIgnore] attribute.

    Please consider using a data transfer object (DTO). For details see the following Microsoft document:

    Create Data Transfer Objects (DTOs)


  2. Michael Taylor 61,201 Reputation points
    2024-07-16T19:39:26.0166667+00:00

    This isn't clear to me. You have a circular dependency issue? What do you mean by cycling problem? Are you getting an error, if so then provide us the error?

    Also provide us sample code to see what you are talking about. At a minimum show us your POCOs that are causing the issue + any entity configurations you're using to map the POCOs to the database. In general the problem is caused by defining relationships on both sets of entities. You should define relationships on only 1 of the entities. EF will handle the bidirectional nature of the relationships.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.