Is it possible to use the .NET Entity Framework with PostGIS?

I've reviewed a few options, including hookup it up with Npgsql using http://npgsql.com/index.php/2009/08/how-to-set-up-entity-framework-npgsql-part-1/, but it appears that the data types in PostGIS are unsupported in Entity Framework.

The closest I can find to a comprehensive statement of what's supported is with Devart's dotConnect for PostgreSQL EF data type mapping at http://www.devart.com/dotconnect/postgresql/docs/DataTypeMapping.html. It appears to expose only base PostgreSQL types and neither PostGIS or presumably common addons like ltree.


Take a look at PostGIS and Entity Framework. The main library for connecting .NET to PostgreSQL is Npgsql, which can be used with (e.g.) SharpMap, NetTopologySuite, GdalOgrInCsharp, etc., depending on what you are doing.

Regarding geometry data types, Npgsql uses System.Byte[] in C# to represent WKB (Well-Known Binary). This byte array type can be selected from PostGIS SQL functions ST_AsBinary(geom) or ST_AsEWKB(geom). Unless you are programming your own custom renderer or data converter, you generally won't need to understand WKB at the byte level. But WKB is useful to pass geometries to other libraries that understand the type without loosing precision of coordinates.

  • 1
    just to complete Mike T's answer. Npgsql 3.0 is out and now handles natively geometry types. An implementation of spatial services providing for the entity framework is on its way too. You can check it out there – tumasgiu Sep 24 '15 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.