Slapper.AutoMapper with Dapper – mapping to spatial types

Slapper.AutoMapper is a really useful mapping tool when using Dapper. I recently needed to convert the spatial datatype SqlGeography from SQL Server to the DbGeography type in Entity Framework.

This is not handled by default in Slapper.AutoMapper and will throw an exception, so this is how to add it.

You need to first create a custom Type Converter.

You then need to register your Type Converter with Slapper:

Then you can happily continue to use Dapper and Slapper.AutoMapper to map your SqlGeography types to .NET types.

One Reply to “Slapper.AutoMapper with Dapper – mapping to spatial types”

Leave a Reply

Your email address will not be published. Required fields are marked *