2014-09-25 63 views
3

我使用的是NHibernate 3.3。我有一個情況,我想插入一個未被引用的計算列。NHibernate空間映射返回Antrl錯誤

我的域實體可以降低到形式

public class Location 
    { 
     public virtual IPoint GeoLocation {get;set;} 
    } 

    public class MappingOverride : IAutoMappingOverride<Location> 
    { 
     public void Override(AutoMapping<Location> mapping) 
     { 
      mapping 
       .Map(e => e.GeoLocation) 
       .Column("GeoLocation") 
       .CustomSqlType("geography") 
       .CustomType<MsSql2008GeographyType>; 
     } 
    } 

表列的類型爲「Geography`

然而,錯誤出作爲

at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes) 
    at System.Reflection.RuntimeAssembly.GetExportedTypes() 
    at GeoAPI.GeometryServiceProvider.GetLoadableTypes(Assembly assembly) 
    at GeoAPI.GeometryServiceProvider.ReflectInstance() 
    at GeoAPI.GeometryServiceProvider.get_Instance() 
    at NetTopologySuite.Geometries.Geometry.set_SRID(Int32 value) 

它說,它需要Antrl.Runtime,但是一個非常舊的版本。那裏的所有Antrl.Runtime nuget軟件包都有不同的程序集標識符。

無法加載文件或程序集'antlr.runtime,Version = 2.7.6.2,Culture = neutral,PublicKeyToken = 1790ba318ebc5d56'或其依賴項之一。該系統找不到指定的文件。

我在一個單獨的項目中工作,我用代碼約定的地圖,它的工作原理沒有任何參考Antrl.Runtime

需要幫助指向自己在朝着正確的方向...

+0

是否有可能使用程序集重定向到更新版本的Antrl?更多信息在這裏(使用log4net作爲例子):http://stackoverflow.com/questions/3158928/referencing-2-differents-versions-of-log4net-in-the-same-solution/3163050#3163050 – DanP 2014-10-06 16:24:57

回答

1

當我嘗試一些東西,工作,裏面也沒有在實際的ASP.NET MVC項目工作的獨立樣本項目。類

定義

public class Location : IEntity 
{ 
    public virtual int Id { get; protected set; } 

    public virtual string LocationName { get; set; } 

    public virtual IPoint GeoLocation { get; set; } 
} 

映射

public class LocationMapping : IAutoMappingOverride<Location> 
{ 
    public void Override(AutoMapping<Location> mapping) 
    { 
     mapping.Map(x => x.LocationName).Column("Name"); 
     mapping.Map(x => x.GeoLocation).Column("GeoLocation") 
       .CustomType<MsSql2008GeographyType>(); 
    } 
} 

測試

public class WhenSavingGeoLocation : BasePersistanceTest 
    { 
     [Test] 
     public void Save() 
     { 
      this.Session 
      .SaveOrUpdate(new Location { 
        LocationName = "Category 01", 
        GeoLocation = new Point(-72.12, 32.2323234) { SRID = 4326 } 
      }); 
     } 
    } 

NHibernate.Spatial使用NetTopologicalSuite其本身是的GeoAPI 衍生物的GeoAPI庫定義一個int erface GeoAPI.Geometries,同時在當前項目中加載/搜索正確的實現失敗,MVC項目中出現Antlr錯誤。

然而,它卻能夠在單獨的示例項目中獲取NetTopologySuite.NtsGeometryServices實現。 GeoAPI中用於搜索實現的實際代碼類似於

 private static IGeometryServices ReflectInstance() 
     { 
#if !PCL 
      var a = AppDomain.CurrentDomain.GetAssemblies(); 
      foreach (var assembly in a) 
      { 
       // Take a look at issue 114: http://code.google.com/p/nettopologysuite/issues/detail?id=114 
       if (assembly is System.Reflection.Emit.AssemblyBuilder) continue; 
       if (assembly.GetType().FullName == "System.Reflection.Emit.InternalAssemblyBuilder") continue; 
       if (assembly.GlobalAssemblyCache && assembly.CodeBase == Assembly.GetExecutingAssembly().CodeBase) continue; 

       foreach (var t in GetLoadableTypes(assembly)) 
       { 
        if (t.IsInterface) continue; 
        if (t.IsAbstract) continue; 
        if (t.IsNotPublic) continue; 
        if (!typeof(IGeometryServices).IsAssignableFrom(t)) continue; 

        var constuctors = t.GetConstructors(); 
        foreach (var constructorInfo in constuctors) 
        { 
         if (constructorInfo.IsPublic && constructorInfo.GetParameters().Length == 0) 
          return (IGeometryServices)Activator.CreateInstance(t); 
        } 
       } 
      } 
#endif 
      throw new InvalidOperationException("Cannot use GeometryServiceProvider without an assigned IGeometryServices class"); 
     } 
    } 

在幾何體上設置SRID時會調用它。我猜測我的MVC項目有一個引用了這個看起來像Antlr的程序集。 有一些建議爲更新的Antlr程序集添加重定向。我也試過,但錯誤仍然不斷重複。