Free Nhibernate Problem (ClassMap)

I have the following XML (.hbm):

<property name="Geometry" column="the_geom">
   <type name="NHibernate.Spatial.Type.GeometryType,NHibernate.Spatial">
      <param name="subtype">MULTIPOLYGON</param>
      <param name="srid">-1</param>
   </type>
</property>

It uses the Nhibernate Spatial type ... How can I map this property using ClassMap (Fluent Nhibernate)?

thanks

+3
source share
1 answer

Well, I did not use NHibernate Spatial, but I looked at the code, and it looks like it GeometryTypeinherits from IUserType so you can use it with.CustomTypeIs<>

For example:

Map(x => x.Geometry, "the_geom").CustomTypeIs<GeometryType>();

If this does not happen automatically, you may not receive your items param. I'm not sure of a really good way to do this, but you can always add an XML change like this:

Map(x => x.Geometry, "the_geom").AddAlteration(p => p.AddElement("type")
    .WithAtt("name", "NHibernate.Spatial.Type.GeometryType,NHibernate.Spatial")
        .AddElement("param")
            .WithAtt("name", "subtype")
            .WithText("MULTIPOLYGON")
        .ParentNode
        .AddElement("param")
            .WithAtt("name", "srid")
            .WithText("-1")
    );

, WithText XmlElement, (WithAtt AddElement FluentNHibernate.Mapping):

public static class XmlExtensions
{
    public static XmlElement WithText(this XmlElement element, string text)
    {
        element.InnerText = text;
        return element;
    }
}
+3

Source: https://habr.com/ru/post/1706001/


All Articles