AuroraDbGeometryToMySqlGeometryPropertyHandler

A property handler that maps the Aurora MySQL spatial types into a MySqlGeometry property.

A property handler that maps the Aurora MySQL spatial types (GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON and GEOMETRYCOLLECTION) into a MySqlGeometry property.

Overview

Name Description
Class AuroraDbGeometryToMySqlGeometryPropertyHandler
Namespace RepoDb.PropertyHandlers.AuroraDb
Package RepoDb.AuroraDb.MySqlConnector
Implements IPropertyHandler<object, MySqlGeometry>
Column type The Aurora MySQL spatial types (GEOMETRY, POINT, LINESTRING, POLYGON, MULTIPOINT, MULTILINESTRING, MULTIPOLYGON and GEOMETRYCOLLECTION)
Property type MySqlGeometry

Conversions

Method Direction Description
Get Database to property Converts the spatial value returned by the driver into a MySqlGeometry. A MySqlGeometry is returned as is, a byte[] (the driver’s internal 4-byte SRID + WKB format) is converted via MySqlGeometry.FromMySql(bytes), and any other value, including null and DBNull, is returned as null.
Set Property to database Passes the MySqlGeometry to the driver as is, which serializes it as its MySQL internal format.

Usability

Bind the handler to the property that maps to a spatial column.

Attribute

public class Place
{
    public int Id { get; set; }

    [Map("location"), PropertyHandler(typeof(AuroraDbGeometryToMySqlGeometryPropertyHandler))]
    public MySqlGeometry Location { get; set; }
}

Once bound, the library invokes the handler automatically when the property is read or written.

using (var connection = new AuroraDbConnection(connectionString))
{
    MySqlGeometry location = GetLocation(); // a MySqlGeometry created via the API of the driver
    connection.Insert(new Place { Id = 1, Location = location });
    var place = connection.Query<Place>(e => e.Id == 1).First();
}

Fluent Mapping

To configure via FluentMapper:

FluentMapper
    .Entity<Place>()
    .PropertyHandler<AuroraDbGeometryToMySqlGeometryPropertyHandler>(e => e.Location);

Property Level Mapping

To configure via PropertyHandlerMapper:

PropertyHandlerMapper.Add<Place, AuroraDbGeometryToMySqlGeometryPropertyHandler>(e => e.Location, new AuroraDbGeometryToMySqlGeometryPropertyHandler(), true);

Type Level Mapping

To apply the handler to every property of the type MySqlGeometry:

PropertyHandlerMapper.Add<MySqlGeometry, AuroraDbGeometryToMySqlGeometryPropertyHandler>(new AuroraDbGeometryToMySqlGeometryPropertyHandler(), true);