Take the 2-minute tour ×
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 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.

share|improve this question

1 Answer 1

up vote 6 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

Your Answer

 
discard

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.