SqlGeography在下一个发行版中,
Dapper.Entityframework软件包
Microsoft.SqlServer.Types核心库。但是,可能有一种方法可以做到这一点。
更新:现在已将其上移到核心库,因此您不需要任何EF引用或
Dapper.Entityframework; 它应该 工作 ;
这已经被推送为Dapper 1.32。
例子:
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; }}


