NHibernate空间映射返回ANTL错误
我使用的是NHibernate 3.3。我有一个例子,我想插入一个未被引用的计算列 我的域实体可以简化为NHibernate空间映射返回ANTL错误,nhibernate,spatial,fluent-nhibernate-mapping,Nhibernate,Spatial,Fluent Nhibernate Mapping,我使用的是NHibernate 3.3。我有一个例子,我想插入一个未被引用的计算列 我的域实体可以简化为 public class Location { public virtual IPoint GeoLocation {get;set;} } public class MappingOverride : IAutoMappingOverride<Location> { public void Overri
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>;
}
}
它说它需要Antrl.Runtime
,但版本非常旧。所有的Antrl.Runtime
numget包都有不同的程序集标识符
无法加载文件或程序集“antlr.runtime,版本=2.7.6.2,区域性=中性,PublicKeyToken=1790ba318ebc5d56”或其依赖项之一。系统找不到指定的文件
我在一个单独的项目中工作,我使用了代码映射约定,它可以在不引用Antrl.Runtime
的情况下工作
需要帮助来指出正确的方向…作为一个单独的示例项目,我尝试了一些有效的方法,但在实际的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>();
}
}
NHibernate.spatical
使用NetTopologicalSuite
,它本身是GeoAPI
GeoAPI库定义了一个接口GeoAPI。几何图形,在当前项目中加载/搜索正确的实现时,由于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程序集添加重定向。我也尝试过,但错误仍在重复。是否可以使用程序集重定向到较新版本的Antll?此处的进一步信息(以log4net为例):
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 }
});
}
}
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");
}
}