我目前正在为 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 配置文件中?如果是这样,怎么办?
谢谢!
最佳答案
无法向 NHibernate 配置文件添加属性,因为它是经过架构验证的(并且您无法更改架构)。
无论如何,除了 NHibernate 核心配置本身之外,这不是放置任何东西的地方。
其他所有内容都应该位于其自己的位置,无论是 app.config
文件中的自定义部分、appSettings
部分中的键等。
关于c# - 如何创建自定义 NHibernate 配置属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2952381/