Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

I've reviewed a few options, including hookup it up with Npgsql using, 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 It appears to expose only base PostgreSQL types and neither PostGIS or presumably common addons like ltree.

share|improve this question

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
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 at 8:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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