Search code examples
.netentity-frameworkpostgresqlpostgisnpgsql

Postgis geography type using Npgsql for EntityFramework


I have a table using the Postgis geography type:

CREATE TABLE Place (
    id SERIAL PRIMARY KEY,
    name TEXT NOT NULL,
    location GEOGRAPHY NOT NULL
);

How do I declare the location field in my entity class?

class Place {
    public long id { get; set; }
    public string name { get; set; }
    public ??? location { get; set; }
}

Of course, I read this question but it was in 2014 and Npsql seems to have evolved to play with Postgis and to support .Net System.Data.Spatial. See the following Npsql issues that are now closed:

I couldn't find a clue in Npsql documentation about how using such features.


Solution

  • Although Npgsql does include PostGIS support, it's partial - not all types are handled, and unfortunately GEOGRAPHY is on of them.

    Here's the relevant issue: https://github.com/npgsql/npgsql/issues/1322, please go post a vote.