[SOLVED] Cannot bind a record to a Patient ID in .NET Core Web Api – Stack Overflow

Issue

This Content is from Stack Overflow. Question asked by Jaser

I’m working on a small .NET Core Web Api project
I’m using repository pattern with entityframework
The project is working fine overall but there is something I don’t understand and
I would appreciate if someone could tell me why it is working properly.

Please look at the attached images

In Swagger UI, I’m creating a new patient record and it is working fine

enter image description here

enter image description here

enter image description here

So far it is working fine – but when I try to bind a record in
the Recommendation Table to an already existing patient – it is not working properly.
It is just creating a new patient with null values.

See images below

enter image description here

enter image description here

enter image description here

enter image description here

Can someone please tell me why this is happening.
I did not post the code here as it would be to much code.
On request – I will post my code



Solution

Check the model of the recommendation class (model for your table). You need to fetch the patient first and then assign the object to the recommendation object then save the changes to the database.


This Question was asked in StackOverflow by Jaser and Answered by Bimade It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?