Geospatial Point Mapping in Fluent NHibernate

我们两清 提交于 2019-12-04 19:51:43

You're using a Geography dialect but using a CustomType of Geometry on your mapping. You should use a custom type of Geography. Something like:

public class PlaceMap : ClassMap<Place>
{
    public PlaceMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);

        Map(x => x.Location).CustomType(typeof(MsSql2008GeographyType)); //for SQL2008
    }
}

Also, there's something else that you may need to do. If your spatial column has an SRID different from 0 (zero), and if you want to skip NH xml mappings, you'll need to declare a custom type like this:

public class Wgs84GeographyType : MsSql2008GeographyType
{
    protected override void SetDefaultSRID(GeoAPI.Geometries.IGeometry geometry)
    {
        geometry.SRID = 4326;
    }
}

And then use it on your mapping:

public class PlaceMap : ClassMap<Place>
{
    public PlaceMap()
    {
        Id(x => x.Id);
        Map(x => x.Name);

        Map(x => x.Location).CustomType(typeof(Wgs84GeographyType));
    }
}

UPDATE:

You should be referencing NHibernate.Spatial.MsSql2008.dll, and I would advise you to use the strongly-typed Dialect method in your database configuration.

.Dialect<MsSql2008GeographyDialect>()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!