I created a model called “Sale”. It has foreign keys such as: “idPerson”, “idCar” and “idReseller”.
But in GET method response body, I receive this structure of response:
{ "id": 1, "idPerson": 1, "person": null, "idCar": 1, "car": null, "idReseller": 1, "reseller": null, "price": 50.00 }
My doubt is: where values are null, shouldn’t id be bringing me the body of the object of that foreign key? I don’t know if this is possible in a get response.
I am using .Net, C# and Sql Server.
I created model like this: (I am using Entity framework, code first)
`using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace CarQuery__Test.Domain.Models
{
public class Sale
{
[Key]
public int Id{ get; set; }
[ForeignKey("Person")]
public int IdPerson { get; set; }
public Person? Person { get; set; }
[ForeignKey("Car")]
public int IdCar { get; set; }
public Car? Car { get; set; }
[ForeignKey("Reseller")]
public int IdReseller { get; set; }
public Reseller? Reseller { get; set; }
public decimal Price { get; set; }
}
}
`
Is ther something wrong?
Thanks in advance.
I was expecting a response with the object, but I don’t know if it is possible.
Giovanni Lucca Reque Uchoa is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.