c# - Fluent NHibernate automap PostGIS geometry type -
given following model:
using nettopologysuite.geometries; public class bounding_box { public virtual int id { get; protected set; } public virtual polygon area { get; set; } }
how automap area
property area geometry(polygon)
column when generating db schema using fluent nhibernate? note not care being able read / update geometry column using nhibernate since using gdal in code.
i know can implementing manual override, i.e.:
public class bounding_boxmappingoverrride : iautomappingoverride<bounding_box> { public void override(automapping<bounding_box> mapping) { mapping.map(x => x.area) .customsqltype("geometry(polygon)"); } }
however, have many tables geometry columns prefer able specify custom type mapping.
for reason, area
property never intercepted following property convention:
public class postgistypesconvention : ipropertyconvention { public void apply(ipropertyinstance instance) { if (instance.type == typeof(polygon)) { instance.customsqltype("geometry(polygon)"); // never reached } } }
i have same problem if use geoapi.geometries.ipolygon
instead of nettopologysuite.geometries.polygon
...
i able resolve defining custom usertypeconvention
, i.e.:
using nettopologysuite.geometries; using nhibernate.spatial.type; public class postgispolygonusertypeconvention : usertypeconvention<postgisgeometrytype> { public override void accept(iacceptancecriteria<ipropertyinspector> criteria) { criteria.expect(c => c.type == typeof(polygon)); } public override void apply(ipropertyinstance instance) { // have set customtype able read/write rows using nhibernate instance.customtype<postgisgeometrytype>(); // have set customsqltype generate correct sql schema instance.customsqltype("geometry(polygon)"); } }
the same principle can used create usertypeconventions
other geometries, such point
, linestring
, multipoint
, etc.
Comments
Post a Comment