IRI.Maptor.Infrastructure.EfCore.PostgreSql
3.0.0-alpha
See the version list below for details.
dotnet add package IRI.Maptor.Infrastructure.EfCore.PostgreSql --version 3.0.0-alpha
NuGet\Install-Package IRI.Maptor.Infrastructure.EfCore.PostgreSql -Version 3.0.0-alpha
<PackageReference Include="IRI.Maptor.Infrastructure.EfCore.PostgreSql" Version="3.0.0-alpha" />
<PackageVersion Include="IRI.Maptor.Infrastructure.EfCore.PostgreSql" Version="3.0.0-alpha" />
<PackageReference Include="IRI.Maptor.Infrastructure.EfCore.PostgreSql" />
paket add IRI.Maptor.Infrastructure.EfCore.PostgreSql --version 3.0.0-alpha
#r "nuget: IRI.Maptor.Infrastructure.EfCore.PostgreSql, 3.0.0-alpha"
#:package IRI.Maptor.Infrastructure.EfCore.PostgreSql@3.0.0-alpha
#addin nuget:?package=IRI.Maptor.Infrastructure.EfCore.PostgreSql&version=3.0.0-alpha&prerelease
#tool nuget:?package=IRI.Maptor.Infrastructure.EfCore.PostgreSql&version=3.0.0-alpha&prerelease
IRI.Maptor.Infrastructure.EfCore.PostgreSql
PostgreSQL/PostGIS support for IRI.Maptor Geometry<Point>, for both EF Core and plain Npgsql. It is the PostGIS
counterpart of IRI.Maptor.Infrastructure.EfCore.SqlServer
and replaces Npgsql's UseNetTopologySuite() without depending on NetTopologySuite. Values move between .NET and
PostGIS as EWKB, which IRI.Maptor.Core.Spatial reads and writes.
The provider-neutral parts (MaptorGeometryValueComparer, ConfigureMaptorGeometry(), IsGeography() /
IsGeometry()) come from IRI.Maptor.Infrastructure.EfCore.
Installation
dotnet add package IRI.Maptor.Infrastructure.EfCore.PostgreSql
Features
- EF Core —
UseMaptor()on the Npgsql provider's options builder mapsGeometry<Point>properties togeometry,geographyor modified types such asgeometry(Polygon,4326). It also adds thepostgisextension to any model with a spatial property, so migrations andEnsureCreatedrunCREATE EXTENSION IF NOT EXISTS postgis. - ADO.NET —
UseMaptor()on anNpgsqlDataSourceBuildermakes Npgsql itself understandGeometry<Point>: parameters, readers (GetFieldValue,GetValue), arrays and binaryCOPY. PostGisGeometrySerializer— converts betweenGeometry<Point>and EWKB, for code that handles the bytes itself.
Usage — EF Core
using IRI.Maptor.Infrastructure.EfCore.Extensions; // ConfigureMaptorGeometry / IsGeometry
using IRI.Maptor.Infrastructure.EfCore.PostgreSql.Extensions; // UseMaptor
options.UseNpgsql(connectionString, x => x.UseMaptor());
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
=> configurationBuilder.ConfigureMaptorGeometry(); // Geometry<Point> -> geography
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Parcel>().Property(e => e.Footprint).HasColumnType("geometry(Polygon,4326)");
modelBuilder.Entity<Parcel>().Property(e => e.LocalShape).IsGeometry();
}
If no column type is configured, Geometry<Point> defaults to geography, as in the SQL Server plugin. The same
DbContext configuration therefore works with either provider.
Migrations work as usual (dotnet ef migrations add, database update, script, remove). The first migration
enables postgis, spatial columns keep their type modifiers, and HasData seed geometries are written as
Geometry<Point>.FromWkt("...", srid) in the migration code. They compare by value, so an unchanged seed never shows up
as a pending model change.
With a connection string, the provider builds its own data source and the plugin is applied to it automatically.
If you hand the context a ready-made NpgsqlDataSource, call UseMaptor() on that data source's builder as well.
Server-side spatial work goes through raw SQL, e.g.
db.Parcels.FromSql($"SELECT * FROM parcels WHERE ST_Intersects(\"Shape\", {area}::geography)"). Interpolated
Geometry<Point> values are sent as geometry, hence the cast. LINQ spatial method translation is not provided.
Usage — ADO.NET
using Npgsql;
using IRI.Maptor.Infrastructure.EfCore.PostgreSql.Extensions;
var builder = new NpgsqlDataSourceBuilder(connectionString);
builder.UseMaptor();
await using var dataSource = builder.Build();
await using var command = dataSource.CreateCommand(
"SELECT geom FROM parcels WHERE ST_Intersects(geom, @area)");
command.Parameters.AddWithValue("area", area); // Geometry<Point>, sent as geometry
await using var reader = await command.ExecuteReaderAsync();
while (await reader.ReadAsync())
{
var geometry = reader.GetFieldValue<Geometry<Point>>(0);
}
An untyped Geometry<Point> parameter is sent as geometry. PostGIS casts it implicitly when the target is a
geography column. To send geography explicitly, set DataTypeName = "geography" on the parameter; EF Core does
this itself, based on the column's type.
Behaviour notes
- SRID — the SRID travels inside the EWKB, so
Geometry<Point>.Sridis preserved in both directions. SRID 0 means "unknown" forgeometry; forgeography, PostGIS treats SRID 0 as 4326. - Z/M —
Geometry<Point>is 2D. Z and M values read from the database are dropped, not rejected. (The SQL Server plugin rejects them instead.) - Experimental Npgsql API — the plugin is built on Npgsql's type-resolver API (
Npgsql.Internal), which Npgsql marks experimental (NPG9001), as its own NetTopologySuite plugin is. Re-test when upgrading Npgsql.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- IRI.Maptor.Infrastructure.EfCore (>= 3.0.0-alpha)
- Npgsql (>= 9.0.3)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 9.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 82 | 11/10/2026 |
| 3.0.0-alpha | 101 | 10/29/2026 |