从SQLServer2008到.NET的映射几何(NHibernate 4.0.0.4000) [英] Mapping Geometry from SQLServer2008 to .NET (NHibernate 4.0.0.4000)

查看:104
本文介绍了从SQLServer2008到.NET的映射几何(NHibernate 4.0.0.4000)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用FluentNHibernate映射SqlServer2008几何体。我正在使用NHibernate版本4.0.0.4000。我使用NUget安装了NHibernate.Spatial,NetTopologySuite,GeoAPI和NHibernate以及FluentNhibernate。

我的Fluent映射看起来像这样:

  public class ArealMap:ClassMap< Areal> 
{
public Areal()
{
表(Areal);
Id(x => x.Id).Column(Id)。GeneratedBy.Identity();
Map(x => x.Geometry).Column(Geometry)。CustomType(typeof(MsSql2008GeometryType));


public class表达式
{
....
公共虚拟几何几何{get;组; }}
}

使用NHibernate 4.0.0.4000 Areal将总是映射为null而不是数据库中的值(类型几何)。非几何属性映射正确。



这个映射在NHibernate 3.3.3中完美运行。
我也加了

$ $ p $ $ $ c $ .Dialect< MsSql2008GeometryDialect>())


以我的流畅配置....

我认为所有的dll都有正确的版本安装,因为我通过NUget得到他们。我不认为它的一个NH / Fluent NH问题,因为我所有的其他映射工作正常... ... $ / b>

是否有一个新的语法映射SQL服务器几何到NHibernate在NH 4.0的发布?我不知道我在想什么。



编辑:

当我将映射更改为:

  Map(x => x.Geometry).Column(Geometry)。CustomType(typeof(MsSqlLegacyGeometryType)); 

我不会在Geometry中得到null,而是我的数据库中的多边形写成
到一个映射为一个几何类型的点与不同的坐标....

我认为这个问题可能是由不同版本的Microsoft.SqlServer.Types beeing使用。 SqlServer2008使用版本10.0和NHibernate.Spatial.MsSql使用版本11.0 ...
或者GeoApi或NetTopologySuite可能会发生重大变化...

编辑:

好​​的,我发现问题的来源....

我正在使用Sql Server所以它使用Microsoft.SqlServer.Types.dll在

$ $ p code> C \Windows\assembly\\GAC_MSIL\ Microsoft.SqlServer.Types\10.0.0.0__89845dcd8080cc91\

但是,NHibernate.Spatial dlls哪个使用NHibernate 4.0期望更高的SQLServer和引用Microsoft.SqlServer.Types.dll版本11中的

  C:\\ Windows \assembly \GAC_MSIL\Microsoft.SqlServer.Types\11.0.0.0_89845dcd8080cc91\ 

任何人都知道如何解决这个问题?



我想我必须检查/克隆其中一个NHibernate.Spatial项目,并手动引用Microsoft.SqlServer.Types.dll版本10,然后重新编译项目...

然而,我失去了作为从哪里开始。我需要什么项目来重新编译? NetTopologySuite是由NHibernate.Spatial引用的还是只有NHibernate.Spatial?

解决方案

虽然可能并不理想,因为它迫使你使用旧版本,我能够通过在web.config的程序集声明中使用绑定重定向来解决NHibernate升级后涉及几何DLLS的不匹配问题。

 <运行时间> 
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =Microsoft.SqlServer.TypespublicKeyToken =89845dcd8080cc91culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-11.0.0.0newVersion =10.0.0.0/>
< / dependentAssembly>
< / assemblyBinding>
< / runtime>


I try to map a SqlServer2008 geometry with FluentNHibernate. I am using NHibernate version 4.0.0.4000. I installed NHibernate.Spatial, NetTopologySuite, GeoAPI and NHibernate with FluentNhibernate all with NUget.

My Fluent mapping looks like this:

public class ArealMap: ClassMap<Areal>
{
    public Areal()
    {
        Table("Areal");
        Id(x => x.Id).Column("Id").GeneratedBy.Identity();
        Map(x => x.Geometry).Column("Geometry").CustomType(typeof(MsSql2008GeometryType));
    }
}
public class Areal 
{
   ....
   public virtual Geometry Geometry{ get; set; }
}

With NHibernate 4.0.0.4000 Areal will always be mapped to null instead of the value in the DB (of type geometry). The non-geometry properties are mapped correctly.

This mapping was working perfectly in NHibernate 3.3.3. I also added

 .Dialect<MsSql2008GeometryDialect>())

to my fluent configuration....

I think all the dlls have the correct version installed, as I got them via NUget. I don´t think its an NH /Fluent NH issue as all my other mappings are working fine...

Is there a new syntax for mapping sql server geometry to NHibernate in the release for NH 4.0? I don´t know what I am missing..

EDIT:

When I change the mapping to:

Map(x => x.Geometry).Column("Geometry").CustomType(typeof(MsSqlLegacyGeometryType));

I don´t get null in Geometry anymore, instead my polygon in database is written to a mapped as a Geometry of type point with different coordinates....

I think this problem might be caused by different versions of Microsoft.SqlServer.Types beeing used... SqlServer2008 uses version 10.0 and NHibernate.Spatial.MsSql uses version 11.0... Or there may be breaking changes in GeoApi or NetTopologySuite...

EDIT:

Okay, I found the source of the problem....

I am using Sql Server 2008, so it uses Microsoft.SqlServer.Types.dll in

C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\10.0.0.0__89845dcd8080cc91\

However, the NHibernate.Spatial dlls which work with NHibernate 4.0 expect higher SQLServer and reference Microsoft.SqlServer.Types.dll version 11 in

C:\Windows\assembly\GAC_MSIL\Microsoft.SqlServer.Types\11.0.0.0_89845dcd8080cc91\

Anyone know how to fix this issue?

I think I have to checkout / clone one of the NHibernate.Spatial projects and manually reference Microsoft.SqlServer.Types.dll version 10 and then recompile the project...

I am lost however as where to start. What projects do I need to reoompile? NetTopologySuite which is referenced by NHibernate.Spatial or only NHibernate.Spatial?

解决方案

While perhaps not ideal since it's forcing you to use an older version, I was able to solve a mismatch involving the Geometry DLLS after an NHibernate upgrade by using a binding redirect on the assembly declaration in the web.config

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
     <dependentAssembly>
      <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="10.0.0.0" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

这篇关于从SQLServer2008到.NET的映射几何(NHibernate 4.0.0.4000)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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