✅ EntityFramework: Navigation property makes a nested object call
So i have transports and categories models/tables , both are connected with a relationship , one category can have many transports and vice versa. Here is my code:
Category model:
Transport model:
The problem is i get this schema in swagger api call:
My category table tries to call another value called "transports" , which i think is from the navigation property in categories model:
The problem fixes itself if i add [JsonIgnore] in my categories model above the navigation line:
but it seems this is a bad practice:
I have tried to dto my Transport model:
but this way it does not return the relationships with category table.
I am kinda lost here , what am i doing wrong?
3 Replies
i am also using dto when returning a single category : (not sure if this even matters here)
swagger shouldn't know about your EF models
your DTOs are projections, the thing you want to expose to people using your software
thanks this actually worked!
I made changes to my transport dto and included
So my final transport dto is