I would like to be able to use Entity Framework with a repository pattern for non-spatial querying of my SDE Sql Server database. I was hoping to reverse code-first engineer the database with the Entity Framework Power Tools to accomplish this.

Has anyone tried this before or something similar? Is it feasible?

A couple issues I've come up with:

  1. The reverse engineering tool doesn't know what to do with the geometry data type in the database, so it skips those columns when generating the POCOs. I'm hoping to get around this by referencing Microsoft.SqlServer.Types.dll (or whatever assembly) and adding a geometry property to my POCOs.
  2. Converting my POCO into an IFeature if I want to do some spatial stuff with it. I'm not sure how I'd set the feature's geometry.
  3. How to handle adding and updating in my EF context. I'd probably make it "read only" so that clients can retrieve data but not commit to it. I have no idea how to handle the versioning, even if it were possible to commit a feature back to the database purely with EF.

3 Answers 3


Sounds like a big ask... for 2) you might look at the WKT to IGeometry functions in my fork of DNRGPS, as well as Earthworm, a .NET ORM for Esri Geodatabase via ArcObjects.


I don't know anything about Entity Framework tools, so I can't help you there. But for (2) I would find an OGC Well Known Binary parser (or roll my own), and use the ST_AsBinary and STGeomFromWKB to read/write the spatial data. I would use WKB and not WKT as I have found precision issues with WKT. For (3) I would look at Esri Versioned Views.

This sounds really interesting.


SDE stores geometry data in image field in SQLServer as a binary stream,so seems you have to add geometry(or) geography type field to your tables and then convert spatial data into this type using one of functions travis mentioned or STGeomFromText. geometry/geography user defined data types in SQLServer2008 are OGC complient as you know,so you can use STAsText() function in your queries and simply pars well known text returned by these queries to achieve spatial data.

here is a simple query i use and pass WKT field inside my spatial class constructors to create my spatial objects.spatial field name is OGIS_Geometry in my tables.

select *,OGIS_Geometry.STAsText() As WKT from mySPatialTableName

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