2011-10-27 61 views
4

我想在LINQ中使用dbgeography的「Intersects」方法(我正在使用EF June 2011 CTP)編寫聯接語句。問題是,如果我寫的是這樣的:空間加入實體框架

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

我收到以下錯誤:

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

在SQL我已經寫了一個類似的查詢如下所以我知道SQL suppports它:

SELECT * FROM Address a 
INNER JOIN SPATIALTABLE b 
WITH(INDEX(geog_sidx)) 
ON b.geom.STIntersects(a.PointGeography) = 1 
+1

您可以在Where子句(ala SQL-82)中嘗試它,而不是使用連接子句嗎? join子句轉換爲Join擴展方法,mnQ不是左側選擇器上的輸入參數。 –

回答

1

嘗試這樣:

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