2011-07-02 39 views
1

我在使用ActiveRecord时遇到了一些问题。ActiveRecord和NHibernate Spatial

那么一切正常,但它有时工作。并非所有的时间。

当我尝试导航到包含空间实体的项目中引用的MVC页面(只有一个空间实体 - 并且此实体没有空间类型)时,我得到此异常。

{ “A GeometryType柱已被声明,但没有配置空间方言”}

有正确配置方言。我试图用两种方式来配置它:Xml和InPlace。

这是我的启动方法:

public static void StartActiveRecord() 
    { 
     IDictionary<string,string> hash = new Dictionary<string,string>(); 

     hash.Add("isWeb", "true"); 
     hash.Add("connection.driver_class","NHibernate.Driver.NpgsqlDriver"); 
     hash.Add("connection.connection_string","Server=localhost;Port=5432;database=nhiber;User ID=postgres;Password=pass;"); 
hash.Add("connection.provider","NHibernate.Connection.DriverConnectionProvider"); 
      hash.Add("dialect","NHibernate.Spatial.Dialect.PostGisDialect,NHibernate.Spatial.PostGis"); 
      hash.Add("proxyfactory.factory_class","NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle"); 

     InPlaceConfigurationSource source = new InPlaceConfigurationSource(); 
     source.Add(typeof(ActiveRecordBase), hash); 
     ActiveRecordStarter.Initialize(source, GetActiveRecordTypes()); 

     foreach (Configuration cfg in ActiveRecordMediator.GetSessionFactoryHolder().GetAllConfigurations()) 
     { 
      cfg.AddAuxiliaryDatabaseObject(new SpatialAuxiliaryDatabaseObject(cfg)); 
      //Metadata.AddMapping(cfg, MetadataClass.GeometryColumn); 
      //Metadata.AddMapping(cfg, MetadataClass.SpatialReferenceSystem); 
     } 
    } 

,这是我的启动方法,在Global.asax中

protected void Application_Start() 
    { 
     Ignition.StartActiveRecord(); 

     AreaRegistration.RegisterAllAreas(); 

     RegisterRoutes(RouteTable.Routes); 
    } 

,有时会出现此错误。杀死开发服务器有时会使其正常,但仅在几步后再次崩溃。

帮助!

编辑:我添加映射到这个问题和其他一些信息

当有方言,这样的错误出Ignition.StartActiveRecord()在Global.asax中。当没有方言时,它在ActiveRecordStarter.Initialize()中出错;

可以肯定的是,下面映射的这个对象是整个程序集中唯一的空间感知对象。

public class Complaint:ActiveRecordBase<Complaint> 
{ 

[PrimaryKey(Column="complaint_id",Generator=PrimaryKeyType.Sequence,SequenceName="complaint_seq")] 
     public virtual int ComplaintId { get; set; } 

     [Property(Column="date_of_complaint",NotNull=true)] 
     public virtual DateTime DateOfComplaint { get; set; } 

     [Property(Column="description",Length=256,NotNull=true)] 
     public virtual string Description { get; set; } 

     [Property(Column="complaint_status",NotNull=true,Default="1")] 
     public cityzenComplaintStatus Status { get; set; } 

     [BelongsTo(Column = "complaint_type_id")] 
     public ComplaintType Type { get; set; } 

     [Property("the_geom", ColumnType = "NHibernate.Spatial.Type.GeometryType, NHibernate.Spatial")] 
     public virtual IGeometry Geometry { get; set; } 

     [OneToOne(ForeignKey="official_answer_id")] 
     public virtual OfficialAnswer CityAnswer { get; set; } 

     [BelongsTo("user_id", Fetch = FetchEnum.Select, Lazy = FetchWhen.OnInvoke, Update = false, NotNull = true)] 
     public virtual CityzenUser User { get; set; } 

     [HasMany(typeof(Vote),Table="vote",ColumnKey="complaint_id",RelationType=RelationType.Set,Inverse=true)] 
     public virtual IList<Vote> Votes { get; set; } 

     [HasMany(typeof(Comment),Table="comment",ColumnKey="complaint_id",RelationType=RelationType.Set,Inverse=true)] 
     public virtual IList<Comment> Comments { get; set; } 

     [Property(Column = "deleted", Default = "false", NotNull = true)] 
     public virtual bool Deleted { get; set; } 
} 
+0

当你拿出的是,在配置具体线路是否可以重现这个问题吗? hash.Add( “方言”, “NHibernate.Spatial.Dialect.PostGisDialect,NHibernate.Spatial.PostGis”); –

+0

我很确定它会抛出一个异常,说没有配置方言。我会试试看。 –

+0

当我删除所述行时,它会在尝试ActiveRecordStarter.Initialize –

回答

1

您的配置看起来正确的给我,但每当NH实例GeometryType的一个实例,它不能找到你被配置为使用,以便它知道你需要初始化(PostGisGeometryType在什么类型的IGeometry的方言是什么原因你案件)。

你可以为一个临时的解决方法做的就是声明你的成员变量是这样的:

[Property("the_geom", ColumnType = "NHibernate.Spatial.Type.PostGisGeometryType, NHibernate.Spatial.PostGis")] 
public virtual IGeometry Geometry { get; set; } 

如果我发现任何东西了,我会回到这里后。

+0

Hello Cole!我会试试这个! –

+0

@George,你有NHibernate.Spatial.PostGis.dll与其他依赖关系在同一目录下吗? –

+0

@George,这项工作或帮助你? –

0

是对的吗? hash.Add(“dialect”,“NHibernate.Spatial.Dialect.PostGisDialect,NHibernate.Spatial.PostGis”); 不应该是这样的: hash.Add(“dialect”,“NHibernate.Spatial.Dialect.PostGisDialect,NHibernate.Spatial”);

采取在偷看:http://nhibernate.info/doc/spatial/configuration-and-mapping.html

+1

不,这是不正确的。类型NHibernate.Spatial.Dialect.PostGisDialect在程序集NHibernate.Spatial中不存在。该配置的格式是类,组装 –

+0

你是完全正确的。但是应用程序可以访问Assembly吗? –

+0

这可能是一个更好的问题。我不确定他会得到他所看到的同样的例外,但是值得一试。 –

相关问题