I'm having problem making a post in swagger. Its a one to many relationship where "Produto" is one.
I have the "Produto", and i shouldn't need any "Material" or "MovimentacaoMaterial", but in swagger i got this huge request body:
My produto Class uses
And i dont really know what is the difference between the ICOllection and just creating a List to reference the classes.
I'm facing this problem for a while now, any help will be very much appreciated! Tanks
10 Replies
The problem is that i cant just pass :
As a request body to make a post
You should request only what's needed, make a new model for such cases
But this model doesnt request all those things right?
I'd assume
ICollection<MovimentacaoProduto>?
Means that it's part of it
Also
$codegifAs for ICollection it's just an interface so it doesn't restrict you only to list and can use other classes which extend
ICollection<T>
cool, first time using disc to ask programming questions, will use this for now on
but doesnt it mean that the body request will not need those other classes to make a postw
It's not about the class of the container there, I'm a bit lost with that response
If you want to pass that collection then just passing an empty one should fix your problem, but if you are not expecting it at all I believe it's better to make a new model for request which doesn't contain it at all
I'm not the most experienced about that so someone else might have a better solution
Its the first time creating a SQL table thats one to many and im a realy lost, i do not have experience creating one to one either, so yeah.
I just wanted to post a "Produto", without needing to create a "Material" or "Movimentacao", but the Swagger API gives me a body request whith all of these.
tried to create the class like this, but swagger still have the same request body
https://www.youtube.com/watch?v=GF4Yag8mytc
found this video that helped me if someone finds the same problem
Naveen Bommidi Tech Seeker
YouTube
Part-3| .NET 7 Web API CRUD Operation Using One-Many Relationship T...
Hi everyone,
This video is about - .NET 7 Web API CRUD Operation Using One-Many Relationship Tables - Implement Creat Operation
The entire session was made as a blog:
https://www.learmoreseekmore.com/2023/03/dotnet7-webapi-crud-operation-using-ont-to-many-relationship-tables.html
Video 1
https://youtu.be/_N_5zxlfrgw
Video 2
https://youtu.be/2...