While working on my project (angular 8 + asp.net 3.0), I encountered a 500 error when attempting to retrieve all Products:
"System.Text.Json.JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32."
I'm not sure where the cycle in my code is occurring. Do I need to redesign all my models? Can someone please clarify what mistake I might be making? The goal was to create CRUD operations for Products, which could then be used to create Dishes. Eventually, users should be able to add products or dishes to their daily menu. Thank you for any assistance.
Here is my modelBuilder below:
modelBuilder.Entity<Ingredient>()
.HasOne(x => x.Dish)
.WithMany(x => x.Ingredients)
.HasForeignKey(x => x.DishId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Ingredient>()
.HasOne(x => x.Product)
.WithMany(x => x.Element)
.HasForeignKey(x => x.ProductId)
.OnDelete(DeleteBehavior.Cascade);
modelBuilder.Entity<Ingredient>()
.HasKey(x => new { x.DishId, x.ProductId });
modelBuilder.Entity<Product>()
.HasOne(x => x.Photo)
.WithMany()
.OnDelete(DeleteBehavior.NoAction);
modelBuilder.Entity<Dish>()
.HasOne(x => x.Photo)
.WithMany()
.OnDelete(DeleteBehavior.NoAction);