共用方式為


SQL Server EF Core 提供者中的空間資料

此頁面包含搭配 Microsoft SQL Server 資料庫提供者使用空間資料的其他資訊。 如需在 EF Core 中使用空間資料的一般資訊,請參閱主要 空間資料 檔。

地理位置或幾何

根據預設,空間屬性會對應至 geography SQL Server 中的資料行。 若要使用 geometry 請在模型中設定資料行類型

地理位置多邊形環形

使用資料 geography 行類型時,SQL Server 會對外部環形(或殼層)和內部環形(或孔)施加額外的需求。 外部環形必須逆時針方向,且內部環形順時針方向。 NetTopologySuite (NTS) 會在將值傳送至資料庫之前先驗證此值。

FullGlobe

使用資料行類型時 geography ,SQL Server 具有非標準幾何類型,表示完整的地球。 它也有一種方法來代表多邊形基於完整的地球(沒有外部環形)。 NTS 不支援這兩者。

警告

NTS 不支援以 FullGlobe 和多邊形為基礎的多邊形。

曲線

如主要 空間資料 檔中所述,NTS 目前無法代表曲線。 這表示在 EF Core 中使用 CircularString、CompoundCurve 和 CurePolygon 值之前,您必須使用 STCurveToLine 方法轉換 CircularString、CompoundCurve 和 CurePolygon 值。

警告

NTS 不支援 CircularString、CompoundCurve 和 CurePolygon。

空間函式對應

下表顯示哪些 NTS 成員會轉譯成哪些 SQL 函式。 請注意,翻譯會根據資料行的類型為 geography 或 geometry 而有所不同。

.NET SQL (geography) SQL (geometry) 已在 中新增
英 孚。Functions.CurveToLine(geometry) @geometry.STCurveToLine() @geometry.STCurveToLine() EF Core 7.0
幾何。地區 @geometry.STArea() @geometry.STArea()
幾何。AsBinary() @geometry.STAsBinary() @geometry.STAsBinary()
幾何。AsText() @geometry.AsTextZM() @geometry.AsTextZM()
幾何。邊界 @geometry.STBoundary()
幾何。緩衝區(距離) @geometry.STBuffer(@distance) @geometry.STBuffer(@distance)
幾何。質心 @geometry.STCentroid()
幾何。Contains(g) @geometry.STContains(@g) @geometry.STContains(@g)
幾何。ConvexHull() @geometry.STConvexHull() @geometry.STConvexHull()
幾何。十字(g) @geometry.STCrosses(@g)
幾何。差異(其他) @geometry.STDifference(@other) @geometry.STDifference(@other)
幾何。維 度 @geometry.STDimension() @geometry.STDimension()
幾何。脫節(g) @geometry.STDisjoint(@g) @geometry.STDisjoint(@g)
幾何。Distance(g) @geometry.STDistance(@g) @geometry.STDistance(@g)
幾何。信封 @geometry.STEnvelope()
幾何。EqualsTopologyly(g) @geometry.STEquals(@g) @geometry.STEquals(@g)
幾何。GeometryType @geometry.STGeometryType() @geometry.STGeometryType()
幾何。GetGeometryN(n) @geometry.STGeometryN(@n + 1) @geometry.STGeometryN(@n + 1)
幾何。InteriorPoint @geometry.STPointOnSurface()
幾何。交集(其他) @geometry.STIntersection(@other) @geometry.STIntersection(@other)
幾何。交集(g) @geometry.STIntersects(@g) @geometry.STIntersects(@g)
幾何。IsEmpty @geometry.STIsEmpty() @geometry.STIsEmpty()
幾何。IsSimple @geometry.STIsSimple()
幾何。IsValid @geometry.STIsValid() @geometry.STIsValid()
幾何。IsWithinDistance(geom, distance) @geometry.STDistance(@geom)<= @distance @geometry.STDistance(@geom)<= @distance
幾何。長度 @geometry.STLength() @geometry.STLength()
幾何。NumGeometries @geometry.STNumGeometries() @geometry.STNumGeometries()
幾何。NumPoints @geometry.STNumPoints() @geometry.STNumPoints()
幾何。OgcGeometryType 當 @geometry.STGeometryType() N'Point' 然後 1 ...結束 當 @geometry.STGeometryType() N'Point' 然後 1 ...結束
幾何。重迭(g) @geometry.STOverlaps(@g) @geometry.STOverlaps(@g)
幾何。PointOnSurface @geometry.STPointOnSurface()
幾何。Relate(g, intersectionPattern) @geometry.STRelate(@g, @intersectionPattern)
幾何。SRID @geometry.STSrid @geometry.STSrid
幾何。SymmetricDifference(其他) @geometry.STSymDifference(@other) @geometry.STSymDifference(@other)
幾何。ToBinary() @geometry.STAsBinary() @geometry.STAsBinary()
幾何。ToText() @geometry.AsTextZM() @geometry.AsTextZM()
幾何。觸控(g) @geometry.STTouches(@g)
幾何。聯盟(其他) @geometry.STUnion(@other) @geometry.STUnion(@other)
幾何。內(g) @geometry.STWithin(@g) @geometry.STWithin(@g)
geometryCollection[i] @geometryCollection.STGeometryN(@i + 1) @geometryCollection.STGeometryN(@i + 1)
geometryCollection.Count @geometryCollection.STNumGeometries() @geometryCollection.STNumGeometries()
lineString.Count @lineString.STNumPoints() @lineString.STNumPoints()
lineString.EndPoint @lineString.STEndPoint() @lineString.STEndPoint()
lineString.GetPointN(n) @lineString.STPointN(@n + 1) @lineString.STPointN(@n + 1)
lineString.IsClosed @lineString.STIsClosed() @lineString.STIsClosed()
lineString.IsRing @lineString.IsRing()
lineString.StartPoint @lineString.STStartPoint() @lineString.STStartPoint()
multiLineString.IsClosed @multiLineString.STIsClosed() @multiLineString.STIsClosed()
點。M @point.M @point.M
點。X @point.Long @point.STX
點。Y @point.Lat @point.STY
點。Z @point.Z @point.Z
多邊形。外部Ring @polygon.RingN(1) @polygon.STExteriorRing()
多邊形。GetInteriorRingN(n) @polygon.RingN(@n + 2) @polygon.STInteriorRingN(@n + 1)
多邊形。NumInteriorRings @polygon.NumRings() -1 @polygon.STNumInteriorRing()

彙總函數

.NET SQL 已在 中新增
GeometryCombiner.Combine(group.Select(x = > x.Property)) CollectionAggregate(屬性) EF Core 7.0
ConvexHull.Create(group.Select(x = > x.Property)) ConvexHullAggregate(屬性) EF Core 7.0
UnaryUnionOp.Union(group.Select(x = > x.Property)) UnionAggregate(屬性) EF Core 7.0
EnvelopeCombiner.CombineAsGeometry(group.Select(x = > x.Property)) EnvelopeAggregate(屬性) EF Core 7.0

其他資源