Self-Referencing Loop When Getting Entity

Really simple question, is there a way to not get related entities in a crudService Get request? In this example, I want to get all ReportSubmissionEntitys but NOT include their related ReportRequestEntitys.

I’m running into a self-referencing error when trying to add the returned list to a JSON response (submission contains request contains submission contains request etc.)

Entity Framework will try to help you out by adding the related entities for you.

You can stop it from doing this by adding .AsNoTracking() before the .Where() in your query.

2 Likes