Cannot map SQL Geography column to EF DbGeography class with dapper

Question

I have table with sql geography column in my SQL database. I have generated entities for my database with EF6. As you know Entitiy Framework generates System.Data.Entity.Spatial.DbGeography for SQL Geography type. I'm using dapper to run queries and map the results into my EF generated entities.

Expert Answer

Dapper has inbuilt support for many common data types, but not all. You might consider using a custom query parameter - you can see how from this commit which adds custom support for table valued parameters as DataTable. I would be very reluctant to add anything that demands additional dependencies, especially for things like EF. What perhaps might be useful in the future is a customisable registration tool for custom providers (allowing the data in the parameters to be anything - moving where the map happens). This does not exist today though.