Reputation: 1444
In my EF data model I have a Location entity and LocationType entity. Location has FkLocationTypeID property. Now if I return a Location object from my API endpoint, it returns a large object which all navigation properties attached to it. Therefore I created a LocationDto to return only those properties I want. My DTO looks something like this:
public class LocationDto
{
public int LocationId { get; set; }
public LocationDto ParentLocation { get; set; }
public LocationType LocationType { get; set; }
public string LocationName { get; set; }
public string LocationCode { get; set; }
// other properties here
}
Now the problem is - I have a LocationType property in my DTO, which is an EF object. The moment I add it, my JSON is again very lengthy, because of all the associations with the LocationType.
Is there'a way to avoid this and only retrieve a LocationType object?
Following is how my json looks like after including the LocationType.
{
"locationId": 0,
"locationType": {
"locationTypeId": 0,
"locationTypeName": "string",
"locationTypeDisplayName": "string",
"localizedKey": "string",
"locations": [
{
"locationId": 0,
"fkParentLocationId": 0,
"fkLocationTypeId": 0,
"fkTimeZoneId": 0,
"locationName": "string",
"locationDisplayName": "string",
"locationCode": "string",
"address1": "string",
"address2": "string",
"city": "string",
"state": "string",
"country": "string",
"zipCode": "string",
"phoneNumber": "string",
"faxNumber": "string",
"phoneExtention": "string",
"email": "string",
"longitude": 0,
"latitude": 0,
"useAppointments": true,
"availabilityWindowDays": 0,
"appointmentCutOffDays": 0,
"dailySummaryEmailTime": "string",
"durationBeforeFirstApptHours": 0,
"reminderBeforeApptSmsHours": 0,
"reminderBeforeApptEmailHours": 0,
"createdBy": 0,
"createdDate": "2018-10-26T06:51:00.288Z",
"changedBy": 0,
"changedDate": "2018-10-26T06:51:00.288Z",
"activeStatus": 0,
"enableStaffSelection": true,
"showInWidget": true,
"autoAssign_FloatPriorityMode": 0,
"googleReserveEnabled": true,
"messageLogs": [
{
"messageLogId": 0,
"fkMessageFormatTypeId": 0,
"fkMessageTypeId": 0,
"fkLocationId": 0,
"fkUserId": 0,
"fkAppointmentId": 0,
"sentTime": "2018-10-26T06:51:00.288Z",
"messageUid": "string",
"messageFormatType": {
"messageFormatTypeId": 0,
"messageFormatTypeName": "string",
"messageTemplates": [
{
"messageTemplateId": 0,
"fkMessageFormatTypeId": 0,
.....................................
}
}
Upvotes: 2
Views: 541
Reputation: 12837
Upvotes: 2