【问题标题】:Adding signed Assembly to nHibernate将签名程序集添加到 nHibernate
【发布时间】:2019-07-10 22:18:31
【问题描述】:

我正在使用 nHibernate。

我制作了一个程序集(例如:DAL.dll),其中包含映射文件(.hbm.xml)和实体(.cs)。这个程序集有一个强名称(签名)。

我创建了一个控制台项目,它引用了 DAL 程序集 (DAL.dll)。

当我尝试实例化配置时,加载我的 DAL 程序集时失败。

错误如下:

NHibernate.MappingException:无法编译映射文档:DAL.Mappings.Cat.hbm.xml NHibernate.MappingException:持久类 DAL.Cat,未找到 DAL

这是控制台应用程序代码:

Configuration cfg = new Configuration();
cfg.SetProperty(Environment.ConnectionDriver, "NHibernate.Driver.SqlClientDriver");
cfg.SetProperty(Environment.ConnectionString, dsn);
cfg.SetProperty(Environment.Dialect, typeof(MsSql2005Dialect).AssemblyQualifiedName);
cfg.SetProperty(Environment.ProxyFactoryFactoryClass, typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedName);
cfg.SetProperty(Environment.ShowSql, "true");
cfg.SetProperty(Environment.ConnectionProvider, typeof(DriverConnectionProvider).AssemblyQualifiedName);
cfg.AddAssembly(typeof(DAL).Assembly);

问题在于 hbm.xml 文件引用了这样的实体:

<class name="DAL.Cat,DAL">

除了使用全名(使用密钥等)引用每个类之外,还有其他解决方案吗

谢谢!

【问题讨论】:

    标签: nhibernate assemblies


    【解决方案1】:

    指定可以帮助您的映射的一种更简洁的方法是:

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                       namespace="DAL"
                       assembly="DAL assembly fully qualified name">
      <class name="Cat">
      ...
    

    但是,即使程序集名称没有限定,这也应该有效。尝试不同的组合,看看会发生什么。

    【讨论】:

    • 这正是我所期望的!非常感谢。
    猜你喜欢
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-18
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多