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

标签 c# nhibernate configuration xsd

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

相关文章:

mysql - MySQL 日志中的虚假信息

c# - 模拟 Windows 用户

c# - Unity3D : C# - Can't seem to handle single/double/hold touches correctly

c# - Azure Function 上的 HttpRequest 不适用于 https

c# - 如何从其他函数和类访问 NH QueryOver 别名?

c# - ASP.NET MVC 和 NHibernate - 使用属性而不是 XML

linux - 如何使用 Apache 和 Yocto 将一个简单的网站构建到嵌入式 Linux 中?

c# - 编译时出现 MonoTouch 错误:System.Boolean System.Type::op_Equality(System.Type,System.Type)

c# - 级联多重关系

java - 在运行时更改 Web 应用程序中的颜色配置