Nhibernate NH空间和Fluent映射
我阅读本文是为了为Nhibernate 3.1编译NH spatial 我也读过这篇文章 但对我来说同样的代码不会编译。。。我有这个Nhibernate NH空间和Fluent映射,nhibernate,fluent-nhibernate,Nhibernate,Fluent Nhibernate,我阅读本文是为了为Nhibernate 3.1编译NH spatial 我也读过这篇文章 但对我来说同样的代码不会编译。。。我有这个 using NetTopologySuite.Geometries; namespace Core { public class District { public virtual int Id { get; set; } public virtual Polygo
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>();
}
}
}
最后
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);
var cfg=new OrderingSystemConfiguration();
var configuration=fluntly.Configure()
.数据库(MsSqlConfiguration.MsSql2008
.ConnectionString(连接字符串)
.方言()
.Mappings(m=>m.AutoMappings.Add(
自动映射装配(cfg)))
.BuildConfiguration();
var exporter=新的SchemaExport(配置);
出口商。下降(假,真);
导出器。创建(true,true);
我有这个错误
NHibernate.MappingException:来自表区的关联引用未映射的类:NetTopologySuite.Geometrics.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; }
}
无论如何,如果这不起作用,请给我一个带测试项目的zip,我会检查它。它非常具体,它说它不能映射多边形类-要么为多边形提供映射,要么告诉fluent忽略它的类似映射(a=>a.Area.CustomType(typeof(NetTopologySuite.geometrics.polygon));我已经映射了(x=>x.Area).CustomType();不要像佩德罗建议我的那样编译。。。这是错误的。映射(m=>m.AutoMappings.Add(AutoMap.AssemblyOf(cfg)),这是正确的。映射(m=>.FluentMappings.AddFromAssemblyOf())然后。。。我正在使用SchemaExport指令来生成数据库模式,我需要在映射上添加一些额外的内容以使其正常工作。。我认为您必须输入一个:.CustomSqlType(“地理”);关于fluentNHibernate映射。现在工作很好,非常感谢!!!
using GeoAPI.Geometries;
public class District
{
public virtual int Id { get; set; }
public virtual IPolygon Area { get; set; }
public virtual string Name { get; set; }
}