Support for SqlGeography
has been added in the next release, again via the Dapper.EntityFramework
package. I haven't built/deployed yet, as I am in two minds as to whether that is the most appropriate assembly for it to live in... but I also don't want to take a dependency on Microsoft.SqlServer.Types
in the core library. There may be a way of doing it without that, though.
Update: this has now moved up a level to the core library, so you shouldn't need any EF references or Dapper.EntityFramework
; it should just work; this has been pushed as Dapper 1.32.
Example:
public void SqlGeography_SO25538154()
{
Dapper.SqlMapper.ResetTypeHandlers(); // to show it doesn't depend on any
connection.Execute("create table #SqlGeo (id int, geo geography)");
var obj = new HazSqlGeo
{
Id = 1,
Geo = SqlGeography.STLineFromText(
new SqlChars(new SqlString(
"LINESTRING(-122.360 47.656, -122.343 47.656 )")), 4326)
};
connection.Execute("insert #SqlGeo(id, geo) values (@Id, @Geo)", obj);
var row = connection.Query<HazSqlGeo>(
"select * from #SqlGeo where id=1").SingleOrDefault();
row.IsNotNull();
row.Id.IsEqualTo(1);
row.Geo.IsNotNull();
}
class HazSqlGeo
{
public int Id { get; set; }
public SqlGeography Geo { get; set; }
}