簡體   English   中英

NHibernatearchitectureid SQL Server 2014

[英]NHibernate hierarchyid SQL Server 2014

我正在通過代碼映射使用NHibernate,並連接了SQL Server。 該服務器還包含文件表。

我為其開發的客戶擁有一個SQL Server 2012,我也有相當一段時間了。 由於運行本地服務器的VM最近出現錯誤,因此我目前正在嘗試針對本地主機(即SQL Server 2014)上的數據庫運行代碼。

我收到了來自客戶數據庫的備份,並將其還原到我的本地服務器中。

在一切順利之前,我的代碼運行沒有大問題。 但是,當我現在嘗試連接到本地數據庫時,NHibernate拋出異常:

列path_locator的sql_pig_pool.dbo.tbl_Abgabebeleg_Dateien中的列類型錯誤。 找到:architectureid,預期為NVARCHAR(255)

當我將連接字符串更改為客戶數據庫時,一切都會恢復。 我認為SQL Server 2012-> 2014中的某些更改,或者工作站上的某種本地配置錯誤。

更新 :我現在在本地安裝了SQL Server 2012,並在那里還原了我的數據庫。 與2014年相同的錯誤。因此差異必須與某些本地配置差異有關。

我的課:

public class TblAbgabebelegDateien
{
    public TblAbgabebelegDateien() { stream_id = Guid.NewGuid(); }
    public virtual string path_locator { get; set; }
    public virtual TblAbgabebelegDateien tbl_AbgabebelegDateienVal { get; set; }
    public virtual Guid stream_id { get; set; }
    public virtual byte[] file_stream { get; set; }
    public virtual string name { get; set; }
    public virtual string file_type { get; set; }
    public virtual long? cached_file_size { get; set; }
    public virtual string creation_time { get; set; }
    public virtual string last_write_time { get; set; }
    public virtual string last_access_time { get; set; }
    public virtual bool is_directory { get; set; }
    public virtual bool is_offline { get; set; }
    public virtual bool is_hidden { get; set; }
    public virtual bool is_readonly { get; set; }
    public virtual bool is_archive { get; set; }
    public virtual bool is_system { get; set; }
    public virtual bool is_temporary { get; set; }
}

我的映射:

public class TblAbgabebelegDateienMap : ClassMapping<TblAbgabebelegDateien> {

    public TblAbgabebelegDateienMap() {
        Schema("dbo");
        Table("tbl_Abgabebeleg_Dateien");
        Lazy(true);
        Id(x => x.path_locator, map => map.Generator(Generators.Assigned));
        Property(x => x.stream_id, map => { map.NotNullable(true); map.Unique(true);  });
        Property(x => x.file_stream);
        Property(x => x.name, map => 
        {
            map.NotNullable(true);
            map.Unique(true);
            map.Length(255);
        });
        Property(x => x.file_type, map => map.Length(255));
        Property(x => x.cached_file_size, map => map.Precision(19));
        Property(x => x.creation_time, map => map.NotNullable(true));
        Property(x => x.last_write_time, map => map.NotNullable(true));
        Property(x => x.last_access_time);
        Property(x => x.is_directory, map => map.NotNullable(true));
        Property(x => x.is_offline, map => map.NotNullable(true));
        Property(x => x.is_hidden, map => map.NotNullable(true));
        Property(x => x.is_readonly, map => map.NotNullable(true));
        Property(x => x.is_archive, map => map.NotNullable(true));
        Property(x => x.is_system, map => map.NotNullable(true));
        Property(x => x.is_temporary, map => map.NotNullable(true));
        ManyToOne(x => x.tbl_AbgabebelegDateienVal, map => 
        {
            map.Column("parent_path_locator");
            map.PropertyRef("path_locator");
            map.Cascade(Cascade.None);
        });
    }
}

有誰知道我應該更改什么,以便我可以再次使用這些表? 我什至不需要路徑定位器(我通過stream_id訪問文件),但這是PK,所以很重要。 NHibernate不喜歡映射中缺少Id屬性。

我只讀取那些表,因此歡迎任何允許我訪問文件表的配置。

我已經看過GitHub-Project( NHibernate.HierarchyId ),但這是用於流暢的映射,而不是用於代碼映射。 我不能在類型的映射中簡單地使用字符串“ hierarchyid”。 我個人嘗試構建IUserType派生的類也失敗了。

附錄:我的本地數據庫上不再有SQL Server Management Studio的子文件夾“索引”。 它仍然可以在我的客戶數據庫上使用(具有3個索引:path_locator上的PK,stream_id上的UQ,parent_path_locator上的UQ +名稱)。 這有任何關系嗎? 更新在新的2012年實例中,此索引文件夾再次可用。

歸結為一個關鍵的區別:

在我的配置IDbIntegrationConfigurationProperties ,我沒有db.SchemaAction我的原始版本定義,但db.SchemaAction = SchemaAutoAction.Validate我現在的版本。

只需刪除驗證即可獲得完整的解決方案。

這個愚蠢的錯誤浪費了數小時。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM