I'm working on a .NET CORE Web API. In the model classes I have a bi-directional reference that upon request throws a Self Referencing Loop Detected error. These are the model classes:
public class Probleem
{
public int Id { get; set; }
[Required]
public Gebruiker Gebruiker { get; set; }
[Required]
public DateTime TimeCreated { get; set; }
}
public class Gebruiker
{
public int Id { get; set; }
[Required]
public String Voornaam { get; set; }
[Required]
public String Naam { get; set; }
[Required]
public List<Probleem> Problemen { get; set; } = new List<Probleem>();
}
The request I am trying to make is a GET request of Probleem, but clearly the code doesn't realize both classes keep referencing each other, causing the crash.
I have read that in order to fix this issue, i need to add code to the Global.asax.cs file, but I can't find the file nor create it in the New Item menu.