I have 2 entities that are related as one to many
public class Restaurant {
public int RestaurantId {get;set;}
public string Name {get;set;}
public
public class Reservation{
public int ReservationId {get;set;}
public int RestaurantId {get;set;}
[JsonIgnore]
public Restaurant Restaurant {get;set;}
Above worked also. But I prefer the following
services.AddControllers().AddNewtonsoftJson(options =>
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
);
Because first we need to add the attribute to all the models we may have the cyclic reference.