再次通過Dapper.EntityFramework
包在下一發行版中添加了對SqlGeography
的支持。我還沒有構建/部署,因爲我有兩個想法:是否最適合它居住......但我也不想在覈心庫中依賴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; }
}
什麼類型?你是直接使用'SqlGeography'嗎?要麼...? – 2014-08-28 06:47:27
相關; http://stackoverflow.com/questions/6690565/using-dapper-with-sql-spatial-types-as-a-parameter/25544690#25544690和http://stackoverflow.com/questions/12090549/mapping-sqlgeography- with-dapper?lq = 1 – 2014-08-28 08:56:44