6

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.

asked Nov 21, 2011 at 19:11

1 Answer 1

9

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.

answered Nov 22, 2011 at 9:04
1
  • 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 Commented Sep 24, 2015 at 8:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.