【问题标题】:How can I create a custom NHibernate configuration property?如何创建自定义 NHibernate 配置属性?
【发布时间】:2011-02-26 11:59:11
【问题描述】:

我目前正在为 HNibernate 创建一个自定义连接提供程序,与提到的here 非常相似。在其中,他们在 hibernate.cfg.xml 参数中指定了一个单独的连接字符串。但是,当我去添加这个新参数时,像这样......

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory>
        <property name="connection.provider">MyNameSpace.FailoverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect,NHibernate</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string">[primary connection string]</property>
        <property name="connection.failover_connection_string">[failover connection string]</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
        ...
    </session-factory>
</hibernate-configuration>

...我收到了这条异常消息:

InnerException  {"The 'name' attribute is invalid - The value 'connection.failover_connection_string' is invalid according to its datatype 'String' - The Enumeration constraint failed."}  System.Exception {System.Xml.Schema.XmlSchemaValidationException}

我的问题是:是否可以将自定义属性添加到 NHibernate 配置文件中?如果有,怎么做?

谢谢!

【问题讨论】:

    标签: c# nhibernate configuration xsd


    【解决方案1】:

    无法将属性添加到 NHibernate 配置文件,因为它已经过架构验证(并且您无法更改架构)。

    无论如何,除了 NHibernate 核心配置本身之外,这不是放置任何东西的地方。

    其他所有内容都应位于其自己的位置,例如 app.config 文件中的自定义部分、appSettings 部分中的键等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多