我在使用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; }
}
當你拿出的是,在配置具體線路是否可以重現這個問題嗎? hash.Add( 「方言」, 「NHibernate.Spatial.Dialect.PostGisDialect,NHibernate.Spatial.PostGis」); –
我很確定它會拋出一個異常,說沒有配置方言。我會試試看。 –
當我刪除所述行時,它會在嘗試ActiveRecordStarter.Initialize –