I am trying to get the Polygon as MySqlGeometry using Dapper.
But the MySql connector understands only MySqlGeometry as Point.
And I need the other types also, like Polygon.
This is what I got from other forums:
// 1. Add Dapper custom Type handler.
Dapper.SqlMapper.AddTypeHandler(new MySqlGeometryTypeHandler());
// 2. Implement that custome handler.
public class MySqlGeometryTypeHandler : SqlMapper.TypeHandler<MySqlGeometry>
{
public override MySqlGeometry Parse(object value) { return new MySqlGeometry(MySqlDbType.Geometry, (byte[])value); }
public override void SetValue(System.Data.IDbDataParameter parameter, MySqlGeometry value) { parameter.Value = value; }
}
// 3. Here is the Data class
public class Geo
{
public int Id { get; set; }
public MySqlGeometry G { get; set; }
}
// 4. Here is the Dapper query
List<Geo> datas = Dapper.SqlMapper.Query<Geo>(cnn, "select * from geo;").ToList();
How do I get the Polygon rows I have in the 'geo' table ?