The reason why serialization fails is your navigation property - while the serializer tries to go through the graph of objects, they lead to cyclic dependencies.
For your simple work example, you have several ways around it.
- Remove
Sheet navigation property from SheetDetail - Wrap objects in ViewModel classes using the Navigation
Sheet omitted property - Create a metadata class using
JsonIgnoreAttribute and then attach it to your entity with a partial class and MetadataTypeAttribute
Here you can find a sample for the third solution (the sample makes some assumptions, because I do not know your exact data types):
public class SheetDetailSerializationMetadata { [JsonIgnore] public Sheet Sheet { get; set; } } [MetadataType(typeof(SheetDetailSerializationMetadata))] public partial class SheetDetail { }
source share