gpt4 book ai didi

c# - 如何创建自定义 NHibernate 配置属性?

转载 作者:行者123 更新时间:2023-11-30 22:45:39 25 4
gpt4 key购买 nike

我目前正在为 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com