Let's say I have these powers with this relationship: This is just a fictitious example, not my current entities.
There are many users in courses, Users have many courses
Courses have a lot of news; NewsPosts has a lot of courses.
Users have a lot of news, NewsPosts have a lot of users
I first use Entity Framework code with the .NET Web API, which dispatches objects in JSON form. When I try to get a course, it sends a JSON result with entites relations, which is good, but I would like to set a limit on the number of levels that it serializes, so it does not serialize all relations outside of the first or second level.
GET Course / will be serialized for:
{ "Users":[{ "id":1, "newsPosts": [{ "id":1, "message":"foo" }] }], "newsPosts":[{ "id":2, "message":"bar" }] }
What I would like is to serialize only 1 or possibly 2 levels so that the result is as follows:
{ "Users":[{ "id":1, "newsPosts": [] }], "newsPosts":[{ "id":2, "message":"bar" }] }
I added:
json.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
This is a link removal.
In short: is there a way to set the maximum number of nodes for serialization?
Are almaas
source share