Skip to content

Spatial Types

Simon Hughes edited this page Aug 30, 2026 · 13 revisions

Spatial Types

Configuration

Spatial types are off by default. The shipped Database.tt sets Settings.DisableGeographyTypes = true, so you have to turn them on:

Enable spatial types:

Settings.DisableGeographyTypes = false;

Disable spatial types (the shipped default):

Settings.DisableGeographyTypes = true;

If DisableGeographyTypes = true and a stored procedure contains spatial parameters or return types, that stored procedure will not be generated.

EF Core 8, 9, and 10

Maps to NetTopologySuite.Geometries.Point / Geometry.

Install NuGet:

Install-Package Microsoft.EntityFrameworkCore.SqlServer.NetTopologySuite

Enable in optionsBuilder:

optionsBuilder.UseSqlServer(@"your_connection_string",
    x => x.UseNetTopologySuite());

Or with DI:

services.AddDbContext<MyDbContext>(options =>
    options.UseSqlServer(connectionString, x => x.UseNetTopologySuite()));

EF 6

Maps to System.Data.Entity.Spatial.DbGeography / DbGeometry. No additional NuGet packages are required.

Other databases

The sections above are SQL Server. What a spatial column maps to depends on the database:

Database Spatial types Maps to
SQL Server geography, geometry NetTopologySuite.Geometries.* (EF Core) / DbGeography, DbGeometry (EF 6)
MySQL / MariaDB geometry, point, linestring, polygon, multipoint, multilinestring, multipolygon, geometrycollection NetTopologySuite.Geometries.*. Needs o.UseMySql(cs, serverVersion, x => x.UseNetTopologySuite())
PostgreSQL geometry, point, line, lseg, box, path, polygon, circle PostgisGeometry and the Npgsql* structs. Add NpgsqlTypes to Settings.AdditionalNamespaces
Oracle sdo_geometry No mapping; set Settings.DisableGeographyTypes = true to skip these columns
SQLite none SpatiaLite is not supported

References

Clone this wiki locally