Cycling problem

Atilla Rüstəmli 40 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.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
749 questions
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,597 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 54,731 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.


  2. SurferOnWww 3,031 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)


Your answer

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