Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spatial Join in Entity Framework

I want to write a join statement in LINQ using the dbgeography's "Intersects" method (I am using EF June 2011 CTP). The problem is if I write something like this:

var joinQuery = from spQ in spatialTableQuery
                    join mnQ in MainQuery
                    on spQ.Polygon.Intersects(mnQ.PointGeography) equals 1

I get the following error:

The name 'mnQ' is not in scope on the left side of 'equals'. Consider swapping the expressions on either side of 'equals'.

In SQL I have written a similar query as below so I know SQL suppports it:

SELECT  * FROM   Address a 
INNER JOIN  SPATIALTABLE b
WITH(INDEX(geog_sidx))
ON b.geom.STIntersects(a.PointGeography) = 1
like image 844
ss_norwalk Avatar asked Nov 05 '22 12:11

ss_norwalk


1 Answers

Try something like this:

var joinQuery = 
   from spQ in spatialTableQuery
   from mnQ in MainQuery
   where spQ.Polygon.Intersects(mnQ.PointGeography) = 1
like image 57
Tom Halladay Avatar answered Nov 09 '22 17:11

Tom Halladay