Buen dia. Actualmente estoy desarrollando una web api en .net core 3.2, cuando hago la peticion a GetBuildingsByApartments Obtengo el resultado de la peticion pero tambien me trae informacion acerca de sistema que no es importante para mi. Solo quiero obtener la clave result que se encuentra en la ultima parte, si alguien pudiera ayudarme le agradeceria:
Anexo la respuesta que obtengo cuando hago la peticion:
"codigo": 200,
"status": "success",
"objeto": {
"stateMachine": {
"<>1__state": 0,
"<>t__builder": {},
"<>4__this": {}
},
"context": {},
"moveNextAction": {
},
"result": [
{
"id": 1,
"name": "Edificio el patio",
"address": "calle 3 numero 17 - 45",
"phone": "8354231",
"country": "Colombia",
"state": "Cauca",
"city": "Popayan",
"apartments": [
{
"id": 12,
"number_apartment": "201",
"phone": "965656",
"number_block": "c",
"buildingId": 1
},
{
"id": 13,
"number_apartment": "202",
"phone": "7654376",
"number_block": "c",
"buildingId": 1
},
{
"id": 14,
"number_apartment": "203",
"phone": "7654376",
"number_block": "c",
"buildingId": 1
},
{
"id": 15,
"number_apartment": "204",
"phone": "876548765",
"number_block": "c",
"buildingId": 1
},
{
"id": 16,
"number_apartment": "205",
"phone": "76548765",
"number_block": "c",
"buildingId": 1
},
{
"id": 17,
"number_apartment": "206",
"phone": "8765476",
"number_block": "c",
"buildingId": 1
},
{
"id": 18,
"number_apartment": "207",
"phone": "8765487",
"number_block": "c",
"buildingId": 1
},
{
"id": 19,
"number_apartment": "208",
"phone": "876576",
"number_block": "c",
"buildingId": 1
}
]
},
{
"id": 2,
"name": "Edificio el quintas de san pedro",
"address": "calle 3 numero 34 - 5",
"phone": "566543",
"country": "Colombia",
"state": "Cauca",
"city": "Cali",
"apartments": [
{
"id": 1,
"number_apartment": "204",
"phone": "876548765",
"number_block": "c",
"buildingId": 2
},
{
"id": 8,
"number_apartment": "208",
"phone": "876576",
"number_block": "c",
"buildingId": 2
},
{
"id": 9,
"number_apartment": "207",
"phone": "8765487",
"number_block": "c",
"buildingId": 2
},
{
"id": 10,
"number_apartment": "206",
"phone": "8765476",
"number_block": "c",
"buildingId": 2
},
{
"id": 11,
"number_apartment": "205",
"phone": "76548765",
"number_block": "c",
"buildingId": 2
},
{
"id": 20,
"number_apartment": "201",
"phone": "965656",
"number_block": "c",
"buildingId": 2
},
{
"id": 21,
"number_apartment": "202",
"phone": "7654376",
"number_block": "c",
"buildingId": 2
},
{
"id": 22,
"number_apartment": "203",
"phone": "7654376",
"number_block": "c",
"buildingId": 2
}
]
},
{
"id": 3,
"name": "Edificio san lorenzo",
"address": "calle 58 numero 23 - 45",
"phone": "8354231",
"country": "Colombia",
"state": "Cauca",
"city": "Popayan",
"apartments": [
{
"id": 2,
"number_apartment": "206",
"phone": "8765476",
"number_block": "c",
"buildingId": 3
},
{
"id": 3,
"number_apartment": "205",
"phone": "76548765",
"number_block": "c",
"buildingId": 3
},
{
"id": 4,
"number_apartment": "204",
"phone": "876548765",
"number_block": "c",
"buildingId": 3
},
{
"id": 5,
"number_apartment": "203",
"phone": "7654376",
"number_block": "c",
"buildingId": 3
},
{
"id": 6,
"number_apartment": "202",
"phone": "7654376",
"number_block": "c",
"buildingId": 3
},
{
"id": 7,
"number_apartment": "201",
"phone": "965656",
"number_block": "c",
"buildingId": 3
},
{
"id": 23,
"number_apartment": "207",
"phone": "8765487",
"number_block": "c",
"buildingId": 3
},
{
"id": 24,
"number_apartment": "208",
"phone": "876576",
"number_block": "c",
"buildingId": 3
}
]
},
{
"id": 4,
"name": "Edificio miraflores",
"address": "calle 3 numero 56 - 11",
"phone": "7654344",
"country": "Colombia",
"state": "Cauca",
"city": "Piendamo",
"apartments": []
},
{
"id": 5,
"name": "Edificio editado popayan",
"address": "calle 3 numero 17 - 45",
"phone": "8354231",
"country": "Colombia",
"state": "Cauca",
"city": "Popayan",
"apartments": []
},
{
"id": 6,
"name": "Edificio editado popayan",
"address": "calle 3 numero 17 - 45",
"phone": "8354231",
"country": "Colombia",
"state": "Cauca",
"city": "Popayan",
"apartments": []
}
],
"id": 108,
"exception": null,
"status": 5,
"isCanceled": false,
"isCompleted": true,
"isCompletedSuccessfully": true,
"creationOptions": 0,
"asyncState": null,
"isFaulted": false
}
Utilizo patron Repository.
BuildingHomeController.cs
[HttpGet]
[Route("ByAparments")]
public IActionResult GetBuildingsByApartments()
{
var result = this.buildingRepository.GetBuildingApartmentAsync();
var returnObject = new
{
codigo = 200,
status = "success",
objeto = result
};
return Ok(returnObject);
}
BuildingRepository.cs
public async Task<IEnumerable<BuildingHome>> GetBuildingApartmentAsync()
{
var result = await context.Building.Include(b => b.Apartments).ToListAsync();
return result;
}
IBuildingRepository.cs
public interface IBuildingRepository : IRepositoryBase<BuildingHome>
{
Task<IEnumerable<BuildingHome>> GetBuildingApartmentAsync();
}