-
Notifications
You must be signed in to change notification settings - Fork 226
Spatial Types
Simon Hughes edited this page Aug 30, 2026
·
13 revisions
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 = trueand a stored procedure contains spatial parameters or return types, that stored procedure will not be generated.
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()));Maps to System.Data.Entity.Spatial.DbGeography / DbGeometry. No additional NuGet packages are required.
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 |
- Settings A-Z - every setting, with a page each
- Common Settings Types Explained
- Settings Callbacks
- Settings runtime values and helpers
- Filtering
- Full Control Over the Generated Code
- Enum Generation from Table Data
- Owned Entities
- JSON column support
- Global Query Filters
- Extended Property Names Feature
- Partial Properties
- File-Scoped Namespaces
- Data Annotations
- Spatial Types
- HierarchyId
- RowVersion and TimeStamp columns
- Lazy Loading
- Stored proc result sets
- Custom File-Based Templates
- Extra entities via partial classes
- INotifyPropertyChanged
- Syntax colour for T4