NHibernate.Spatial和SQL 2008地理类型 - 如何配置 [英] NHibernate.Spatial and Sql 2008 Geography type - How to configure

查看:446
本文介绍了NHibernate.Spatial和SQL 2008地理类型 - 如何配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用NHibernate的与SQL 2008地理类型和时遇到的困难。我使用流利的NHibernate的配置,我是相当新的,这样可能是问题,以及

I am trying to use Nhibernate with the Sql 2008 Geography type and am having difficulty. I am using Fluent Nhibernate to configure which I am fairly new to so that may be the problem as well.

首先,我想坚持的类看起来是这样的:

First, the class I am trying to persist looks something like:

public class LocationLog : FluentNHibernate.Data.Entity
{
   public virtual new int Id {get;set;}
   public virtual DateTime TimeStamp {get;set;}
   public virtual GisSharpBlog.NetTopologySuite.Geometries.Point Location {get;set;}
}

映射类是这样的:

public class LocationLogMap : ClassMap<LocationLog>
{
   ImportType<GisSharpBlog.NetTopologySuite.Geometries.Point>();
   Id(x => x.Id);
   Map(x => x.TimeStamp).Generated.Insert();
   Map(x => x.Location);
}

在为了使用功能NHibernate的MsSql2008GeographyDialect,我已经创建了自己的配置类:

In order to use the MsSql2008GeographyDialect with Fluent Nhibernate, I have created my own configuration class:

public class Sql2008Configuration
  : PersistenceConfiguration<Sql2008Configuration, MsSqlConnectionStringBuilder>
{
   public Sql2008Configuration()
   {
      Driver<SqlClientDriver>();
   }

   public static Sql2008Configuration MsSql2008
   {
      get { return new Sql2008Configuration().Dialect<MsSql2008GeographyDialect>(); }
   }
}



所以我有这样的配置代码:

so I have configuration code like:

var configuration = Fluently.Configure()
  .Database(Sql2008Configuration.MsSql2008.ConnectionString(c => c.Is(connectionString)))
  .Mappings(m => m.FluentMappings
    .AddFromAssemblyOf<LocationLog>()
);



所有这些设置的事实,我正试图坚持的LocationLog类型时,下面的错误到数据库:

All of this to setup the fact that I am getting the following error when trying to persist the LocationLog type to the database:

用户定义的例程或
的合计
执行过程中发生的.NET Framework错误地理志:
System.ArgumentException:24204:在
空间参考标识符(SRID)是
无效。指定的SRID必须$在
sys.spatial_reference_systems目录
视图中显示的支持SRIDs
的B $ B匹配之一。 System.ArgumentException:在在
Microsoft.SqlServer.Types.SqlGeography.Read
Microsoft.SqlServer.Types.SqlGeography.set_Srid(的Int32
值)(BinaryReader
R)在
SqlGeography ::。DeserializeValidate(IntPtr的
,的Int32,CClrLobContext *)

A .NET Framework error occurred during execution of user-defined routine or aggregate "geography": System.ArgumentException: 24204: The spatial reference identifier (SRID) is not valid. The specified SRID must match one of the supported SRIDs displayed in the sys.spatial_reference_systems catalog view. System.ArgumentException: at Microsoft.SqlServer.Types.SqlGeography.set_Srid(Int32 value) at Microsoft.SqlServer.Types.SqlGeography.Read(BinaryReader r) at SqlGeography::.DeserializeValidate(IntPtr , Int32 , CClrLobContext* )

我读到有关如何在下面的文章配置和使用NHibernate的空间库:

I have read the following articles about how to configure and use the Nhibernate Spatial libraries:

  • http://nhibernate.info/doc/spatial/configuration-and-mapping.html
  • http://nhibernate.info/doc/spatial/sample-usage.html

但也没什么帮助。任何人有经验配置NHibernate的使用空间地理类型谁可以提供任何见解将不胜感激。

but neither seem to help. Anybody that has experience configuring Nhibernate to use the Spatial Geography types who could provide any insights would be greatly appreciated.

推荐答案

我在同一条船上,并感谢你的开始我得到它的工作(插入和阅读空间数据)。对于任何人谁是有兴趣,首先将GisSharpBlog.NetTopologySuite.Geometries.Point类是在NetTopologySuite.dll这是nHibernate.Spatial下载的一部分。

I am in the same boat, and thanks to your start I got it working (inserting and reading spatial data). For anyone else who is interested, firstly the GisSharpBlog.NetTopologySuite.Geometries.Point class is in NetTopologySuite.dll which is part of the nHibernate.Spatial download.

其次,根据詹姆斯点,请确保您设定的SRID为4326。

Secondly, as per James point, make sure you set the SRID to 4326.

和最后,地图需要看起来像这样:

And lastly, the map needs to look like this:

Map(a => a.Location).CustomType(typeof(NHibernate.Spatial.Type.GeometryType));



我使用的地理,但我读的地方,使用GeometryType可以工作,它为我(我插入一些点和在数据库中验证它)。我也看了,它的最好写SQL查询对地理,这样就可以使用特殊的SQL 2008空间的方法(而不是使用标准)。

I am using Geography, but I read somewhere that using GeometryType may work and it does for me (I inserted some points and verified it in the database). I also read that its best to write SQL Query's for Geography so that you can use the special SQL 2008 Spatial methods (as opposed to using Criteria).

这篇关于NHibernate.Spatial和SQL 2008地理类型 - 如何配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆