I'm making project about having 2 or more people can make an appointment to each other. everything work fine, but I just realize that some data from foreign key automatically loaded even though I didn't include it in code.
This is the result from API that I made
{
"uId": 1,
"userId": "xxxx",
"receiveAppointmentForms": [],
"requestAppointmentForms": [
{
...Some infomation,
"receiveUser": {
"uId": 2,
"userId": "zzz",
"receiveAppointmentForms": [],
"requestAppointmentForms": null,
"topThrees": null,
"userRole": null,
"coach": null,
"department": null,
"position": null
},
"record": null
}
],
"userRole": null,
"coach": null,
"department": null,
"position": null
},
So I did include "requestAppointmentForms" field, but I don't want the "receiveUser", which is the foreign key refers to the User table, to be shown. because I didn't use that information on my web page and it makes the request slower cause it has a lot of data.
Here is my code on the controller
[HttpGet]
public IEnumerable<User> GetUsers()
{
return _context.Users.Include( r => r.ReceiveAppointmentForms)
.Include(r => r.RequestAppointmentForms);
}
Code from appointmentform model
[Key]
public int AppointmentFormId { get; set; }
public string AppointmentDate { get; set; }
public DateTime AppointmentDateRequest { get; set; }
public string AppointmentTimeStart { get; set; }
public string AppointmentStatus { get; set; }
public string AppointmentCancelComment { get; set; }
public int? RequestUserId { get; set; }
public int? ReceiveUserId { get; set; }
public User RequestUser { get; set; }
public User ReceiveUser { get; set; }
public AppointmentRecord Record { get; set; }