public async Task <IActionResult> GetProperties() { /* Get the properties from the asset repo */ var properties = await _repo.GetCompaniesPropertiesAsync(); foreach (var propertry in properties) { /* Refrences to related entities*/ var companyCode = propertry.CompanyId.GetValueOrDefault(); propertry.Company = _repo.GetCompany(companyCode); var userCode = propertry.UserId.GetValueOrDefault(); propertry.User = _repo.GetUserSync(userCode); var provinceCode = propertry.ProvinceId.GetValueOrDefault(); propertry.Province = _repo.GetProvince(provinceCode); var cityCode = propertry.CityId.GetValueOrDefault(); propertry.City = _repo.GetCity(cityCode); } /* Return the properties*/ var propertiesToReturn = _mapper.Map <IEnumerable <PropertiesToReturnDto> >(properties); return(Ok(propertiesToReturn)); }