我已经阅读了这篇文章,以便为Nhibernate 3.1编译NH空间
http://build-failed.blogspot.it/2012/02/nhibernate-spatial-part-2.html
我也读过这个
NHibernate.Spatial and Sql 2008 Geography type - How to configure
但是我的代码不能编译......我有这个
using NetTopologySuite.Geometries;
namespace Core
{
public class District
{
public virtual int Id { get; set; }
public virtual Polygon Area { get; set; }
public virtual string Name { get; set; }
}
}
using Core;
using FluentNHibernate.Mapping;
namespace TestNHSpatial
{
public class DistrictMap : ClassMap<District>
{
public DistrictMap()
{
ImportType<NetTopologySuite.Geometries.Point>();
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Area).CustomType<Wgs84GeographyType>();
}
}
}
和这个
[Serializable]
public class Wgs84GeographyType : MsSql2008GeographyType
{
protected override void SetDefaultSRID(GeoAPI.Geometries.IGeometry geometry)
{
geometry.SRID = 4326;
}
}
最后
var cfg = new OrderingSystemConfiguration();
var configuration = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(connString)
.Dialect<MsSql2008GeographyDialect>())
.Mappings(m => m.AutoMappings.Add(
AutoMap.AssemblyOf<District>(cfg)))
.BuildConfiguration();
var exporter = new SchemaExport(configuration);
exporter.Drop(false, true);
exporter.Create(true, true);
我有这个错误......
NHibernate.MappingException:表区中的关联引用了未映射的类:NetTopologySuite.Geometries.Polygon
任何人都可以帮助我吗?
感谢
答案 0 :(得分:1)
代码有一些问题,即:
我是您推荐的博文的作者。
将类型从Polygon(从NetTopologySuite)更改为IPolygon(来自GeoAPI)。
应该是这样的:
using GeoAPI.Geometries;
public class District
{
public virtual int Id { get; set; }
public virtual IPolygon Area { get; set; }
public virtual string Name { get; set; }
}
无论如何,如果这不起作用,请给我一个带测试项目的拉链,我会检查出来。