I am working on an ASP.NET Core 6 Web API application with Entity Framework Core. I have entities AssetsCategoryMaster and Users. AssetsCategoryMaster has a reference navigation property for Users (CreatedBy) and Users has a collection navigation property for AssetsCategoryMaster (AssetsCategoryCreatedList).
I just query AssetsCategory as shown here:
var AssetCategoryList = await _context.Set<AssetsCategoryMaster>()
.Where(p => !p.IsDeleted).ToListAsync();
I noticed by default the Users (CreatedBy) loaded with AssetCategory, and inside the CreatedBy, I can see AssetsCategoryCreatedList also loaded.
API call results in this error:
System.Text.Json.JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to support cycles. Path: $.CreatedBy.AssetsCategoryCreatedList.CreatedBy.AssetsCategoryCreatedList.CreatedBy.AssetsCategoryCreatedList.CreatedBy.AssetsCategoryCreatedList.CreatedBy.AssetsCategoryCreatedList.CreatedBy.AssetsCategoryCreatedList.CreatedBy.AssetsCategoryCreatedList.CreatedBy.AssetsCategoryCreatedList.CreatedBy.AssetsCategoryCreatedList.CreatedBy.AssetsCategoryCreatedList.AssetCategoryName.......
The related entities are loaded without use of .Include. I m not sure what I'm doing wrong.
Could anyone help me with this?