Fluent NHibernate 中的地理空间点映射
我正在努力让 Fluent NHibernate 与 SQL Server 的地理空间类型很好地配合。我想在我的 Place
类中存储一个地理点,但是当我运行 ASP.NET MVC 应用程序时,我不断收到 NHibernate 配置错误:
Method 'SetParameterValues' in type 'NHibernate.Spatial.Type.GeometryType' from
assembly 'NHibernate.Spatial, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' does not have an implementation.
更新:这是由过时的 NHibernate.Spatial DLL。引用最新版本(2.2+)解决了该问题。感谢 psousa 引导我找到解决方案。
Place
类:
using System;
using GisSharpBlog.NetTopologySuite.Geometries;
using NHibernate.Validator.Constraints;
namespace MyApp.Data.Entities
{
public class Place
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual Point Location { get; set; }
}
}
Fluent Place
映射:
using MyApp.Data.Entities;
using FluentNHibernate.Mapping;
using NHibernate.Spatial.Type;
namespace MyApp.Data.Mappings
{
public class PlaceMap : ClassMap<Place>
{
public PlaceMap()
{
ImportType<GisSharpBlog.NetTopologySuite.Geometries.Point>();
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Location)
.CustomType(typeof(GeometryType));
}
}
}
Fluent NHibernate 配置:
var cfg = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey(connectionStringKey))
.ShowSql()
.Dialect("NHibernate.Spatial.Dialect.MsSql2008GeographyDialect,NHibernate.Spatial.MsSql2008"))
.ExposeConfiguration(BuildSchema)
.Mappings(x => x.FluentMappings.AddFromAssembly(typeof(UserMap).Assembly)
.Conventions.AddFromAssemblyOf<ColumnNullabilityConvention>());
I'm struggling to get Fluent NHibernate to play nice with SQL Server's Geospatial types. I want to store a geographic point in my Place
class, but I keep getting an NHibernate configuration error when I run my ASP.NET MVC app:
Method 'SetParameterValues' in type 'NHibernate.Spatial.Type.GeometryType' from
assembly 'NHibernate.Spatial, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' does not have an implementation.
Update: This is caused by an out-dated NHibernate.Spatial DLL. Referencing the latest version (2.2+) solves the problem. Kudos to psousa for leading me to a solution.
Place
class:
using System;
using GisSharpBlog.NetTopologySuite.Geometries;
using NHibernate.Validator.Constraints;
namespace MyApp.Data.Entities
{
public class Place
{
public virtual Guid Id { get; set; }
public virtual string Name { get; set; }
public virtual Point Location { get; set; }
}
}
Fluent Place
Mapping:
using MyApp.Data.Entities;
using FluentNHibernate.Mapping;
using NHibernate.Spatial.Type;
namespace MyApp.Data.Mappings
{
public class PlaceMap : ClassMap<Place>
{
public PlaceMap()
{
ImportType<GisSharpBlog.NetTopologySuite.Geometries.Point>();
Id(x => x.Id);
Map(x => x.Name);
Map(x => x.Location)
.CustomType(typeof(GeometryType));
}
}
}
Fluent NHibernate Configuration:
var cfg = Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008
.ConnectionString(c => c.FromConnectionStringWithKey(connectionStringKey))
.ShowSql()
.Dialect("NHibernate.Spatial.Dialect.MsSql2008GeographyDialect,NHibernate.Spatial.MsSql2008"))
.ExposeConfiguration(BuildSchema)
.Mappings(x => x.FluentMappings.AddFromAssembly(typeof(UserMap).Assembly)
.Conventions.AddFromAssemblyOf<ColumnNullabilityConvention>());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用地理方言,但在地图上使用几何的自定义类型。您应该使用自定义类型的地理。例如:
此外,您可能还需要做其他事情。如果您的空间列的 SRID 不同于 0(零),并且如果您想跳过 NH xml 映射,则需要声明如下自定义类型:
然后在映射中使用它:
UPDATE:< /strong>
您应该引用 NHibernate.Spatial.MsSql2008.dll,我建议您在数据库配置中使用强类型 Dialect 方法。
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:
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:
And then use it on your mapping:
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.