// Methods for getting catchments for a point (e.g. for anomaly catchment assignment or goastbusters) private async Task <List <CatchmentEntity> > GetCatchmentEntitiesContainingPoint(LngLat lngLat) { var catchmentEntities = await this.ExecuteInContextAsyncWithGeometryFactory(async (dbContext, geometryFactory) => { var coordinate = lngLat.ToCoordinate(); var point = geometryFactory.CreatePoint(coordinate); var relevantGridUnitIdentityValues = await dbContext.GridUnits .Where(x => x.Boundary.Contains(point)) .Select(x => x.GUID) .ToListAsync(); IQueryable <CatchmentEntity> result; if (relevantGridUnitIdentityValues.IsEmpty()) { // Search all catchments. This may take a while. result = dbContext.Catchments .Where(x => x.Boundary.Contains(point)); } else { result = from catchment in dbContext.Catchments join catchmentGridUnit in dbContext.CatchmentGridUnits on catchment.Identity equals catchmentGridUnit.CatchmentIdentity where relevantGridUnitIdentityValues.Contains(catchmentGridUnit.GridUnitIdentity) where catchment.Boundary.Contains(point) select catchment; } return(await result.ToListAsync()); }); return(catchmentEntities); }