✅ ASP Net 7 - Return list of objects as an object with a nested list
I have an endpoint with the following code:
This returns a list like:
I want to return:
```
5 Replies
so put your
List<Page>
in an object 🤷
also can you consider not returning your raw db object from a controller?
there are probably fields in there that shouldn't be given to the world to see
instead you could build a model specifically for this needUnknown User•10mo ago
Message Not Public
Sign In & Join Server To View
There's no fields in the DB object that need to be kept hidden:
but I assume there should be a second class called PageDto to send to the client?
There's no fields in the DB object that need to be kept hidden:we could argue about
Id
but anyway the dto could have some specific attributes for serialization, for example
also it could be a specific dto for a feature instead of the whole thing, which could help keep stuff organized
(say you event only want a dto for creating and one for retrieving the model)I have an endpoint called /api/pages/{id} where users can pass a pageId to get that specific page, but I can see why it would be hidden in other cases