diff --git a/src/LocationByZip/SqlLocationRepository.cs b/src/LocationByZip/SqlLocationRepository.cs index c4c4080..69ae5ac 100644 --- a/src/LocationByZip/SqlLocationRepository.cs +++ b/src/LocationByZip/SqlLocationRepository.cs @@ -60,6 +60,7 @@ public async Task> GetByCityStateAsync(string city /// within Radius miles of inRefLoc. public async Task> GetLocationsInRadiusAsync(Location origin, RadiusBox bounds) { + var locationsInBoundingBox = new List(); var locationsInRadius = new List(); using (var conn = new SqlConnection(_connectionString)) @@ -72,17 +73,16 @@ public async Task> GetLocationsInRadiusAsy EastLon = bounds.RightLongitude, }; - var locs = (await conn.QueryAsync(GetLocationsWithinRadiusSql(), args)) - .ToArray(); + locationsInBoundingBox.AddRange(await conn.QueryAsync(GetLocationsWithinRadiusSql(), args)); + } - foreach (var loc in locs) - { - loc.DistanceToCenter = loc.DistanceFrom(origin); + foreach (var locInBox in locationsInBoundingBox) + { + locInBox.DistanceToCenter = locInBox.DistanceFrom(origin); - if (loc.DistanceToCenter <= bounds.RadiusMiles) - { - locationsInRadius.Add(loc); - } + if (locInBox.DistanceToCenter <= bounds.RadiusMiles) + { + locationsInRadius.Add(locInBox); } }