在Asp.net Web.Api项目中使用Geograp与NHibernate.Spatial

时间:2015-08-11 07:41:43

标签: c# nhibernate asp.net-web-api2 nhibernate-mapping geography

我在Web.Api项目中使用NHibernate并开始实现地理数据处理的逻辑。我正在关注Nhibernate的一篇文章Spatial,但我的配置出了问题。我不明白为什么。我的配置部分:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
  <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle</property>
  <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
  <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
  <property name="connection.connection_string_name">DefaultConnection</property>
  <!--<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>-->
  <property name="dialect">NHibernate.Spatial.Dialect.MsSql2008GeographyDialect,NHibernate.Spatial.MsSql</property>
  <property name="current_session_context_class">web</property>
  <property name="show_sql">true</property>
  <property name="command_timeout">120</property>
  <mapping assembly="GeoMail.Core" />
</session-factory>

课堂上的属性:

public virtual NetTopologySuite.Geometries.Point Geo { get; set; }

它的映射:

<property name="Geo" column="geo" >
  <type name="NHibernate.Spatial.Type.GeometryType, NHibernate.Spatial">
    <param name="srid">4326</param>
    <param name="subtype">POINT</param>
  </type>
</property>

额外配置:

 private void InitSessionFactory()
    {
        var cfg = new Configuration().Configure();
        cfg.AddAuxiliaryDatabaseObject( new SpatialAuxiliaryDatabaseObject( cfg ) );
        Metadata.AddMapping( cfg, MetadataClass.GeometryColumn );
        Metadata.AddMapping( cfg, MetadataClass.SpatialReferenceSystem );

        sessionFactory = cfg.BuildSessionFactory();
    } 

但我总是得到这个错误: 未找到资源: NHibernate.Spatial.Metadata.SpatialReferenceSystem.MsSql2008GeographyDialect.hbm.xml 但! 查看装配我们可以找到: - System.Reflection.Assembly.Load(“NHibernate.Spatial.MsSql”)。GetManifestResourceNames()          [0]“NHibernate.Spatial.Metadata.GeometryColumn.MsSql2008GeographyDialect.hbm.xml”
        1“NHibernate.Spatial.Metadata.GeometryColumn.MsSql2008GeometryDialect.hbm.xml”
        [2]“NHibernate.Spatial.Metadata.SpatialReferenceSystem.MsSqlLegacyDialect.hbm.xml”         [3]“NHibernate.Spatial.Metadata.GeometryColumn.MsSqlLegacyDialect.hbm.xml”

为什么图书馆正在寻找缺少的资源?

如果不添加映射MetadataClass.SpatialReferenceSystem属性Geo始终返回null。 安装包:

 <package id="GeoAPI" version="1.7.3" targetFramework="net45" />
 <package id="Iesi.Collections" version="4.0.0.4000" targetFramework="net45" /> 
 <package id="Microsoft.SqlServer.Types" version="11.0.1" targetFramework="net45" />     
 <package id="NetTopologySuite" version="1.13.3.2" targetFramework="net45" />
 <package id="NetTopologySuite.IO" version="1.13.3.2" targetFramework="net45" />
 <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
 <package id="NHibernate" version="4.0.0.4000" targetFramework="net45" />
 <package id="NHibernate.Spatial.MsSql" version="4.0.3.4000" targetFramework="net45" />
 <package id="System.Spatial" version="5.6.2" targetFramework="net45" />

虽然我没有使用Spatial命名空间和方言项目进展顺利。但现在我不知道该怎么做......

0 个答案:

没有答案