繁体   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