Dapper映射SQL Server空间类型

时间:2012-05-03 10:35:39

标签: spatial dapper

是否可以使用Dapper从具有空间类型列(几何类型)的表中选择行? 映射的类型应该是SqlGeometry。

我只需要做简单的SQL查询

SELECT * FROM [table] WHERE ID = @ID

我的POCO类与此类似

public class DbFinca
{
        public int ID { get; set; }
        public string B { get; set; }
        public int C { get; set; }
        public SqlGeometry Geometry { get; set; }
}

抱歉,这是一个错误。 它没有问题。

*的 *更新 这是代码片段。非常简单。

    var ID = 1;
    var sql = "SELECT * FROM Fincas WHERE ID=@ID";
    var result = con.Query<DbFinca>(sql, new { ID });
    var dbFinca = result.FirstOrDefault();
    if (dbFinca != null)
    {
        var wkt = new string(dbFinca.Geometry.STAsText().Value);
        Log2("WKT: {0}", wkt);
    }

这会将其发送到日志

WKT:MULTIPOLYGON(((-2.9666920205950991 43.141191073285114,-2.9663227211153171 43.14132413186703,-2.9663105180955376 43.141324992899406,-2.965924442787363 43.141192857740812,-2.9660856223456458 43.140868052633735,-2.9662564271631018 43.140919700987695,-2.966168161166999 43.141083974950007,-2.9663169205235151 43.141140804931474,-2.9664657471480709 43.141078876918627,-2.9664224499824989 43.14107540485081, - 2.9664406135058057 43.140975100351312,-2.9666728323318154 43.1410135072864,-2.9666920205950991 43.141191073285114)))

0 个答案:

没有答案