Nhibernate web.config转换未应用于特殊节
我不熟悉web.config转换,但它可以用于我的连接字符串。但是,未应用自定义节(nhibernate)的my变换。以下是转换文件:Nhibernate web.config转换未应用于特殊节,nhibernate,asp.net-mvc-2,Nhibernate,Asp.net Mvc 2,我不熟悉web.config转换,但它可以用于我的连接字符串。但是,未应用自定义节(nhibernate)的my变换。以下是转换文件: <?xml version="1.0"?> <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> <configuration xmlns:xdt="
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="ApplicationServices"
connectionString="Data Source=.\SQLEXPRESS;Database=msmri_Users;UID=myuser;pwd=mypass;"
providerName="System.Data.SqlClient" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
<appSettings>
<add key="TableStorageEndpoint" value="http://127.0.0.1:10002/devstoreaccount1" xdt:Transform="Remove" xdt:Locator="Match(key)" />
</appSettings>
数据源=。\SQLEXPRESS;数据库=mydb;UID=myuser;pwd=mypass;
所有想法都受到赞赏。谢谢 当然,这并不适用于所有情况,但根据我上面的评论,如果确实不支持,我的解决方案是在ConnectionString下添加连接字符串,并从hibernate配置部分引用它。然后,我的转换仍在其中一个默认配置部分中进行。我仍然希望听到这不是一个真正的限制 延迟更新:因此,这里的问题是包含xmlns属性的部分-配置转换不会处理这些属性。在某些情况下(例如,对于assemblyBinding部分),如果存在包含元素,解决方法是对父元素使用Transform=“Replace”,如下所示:
<runtime xdt:Transform="Replace">
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="MySql.Data"
fullName="MySql.Data, Version=6.2.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
</qualifyAssembly>
</assemblyBinding>
</runtime>
这仍然不适用于我的nhibernate部分,它唯一的父元素是配置元素本身,但是 诀窍是将xml名称空间添加到转换配置中 下面是Web.config的示例设置:
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
...
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
...
<property name="show_sql">true</property>
...
</session-factory>
</hibernate-configuration>
...
...
真的
...
现在将xml名称空间添加到转换配置中。(例如Web.Release.config):
...
假的
现在应该按您希望的方式替换代码。this()表示不支持此操作,这将是非常蹩脚的
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
...
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
...
<property name="show_sql">true</property>
...
</session-factory>
</hibernate-configuration>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
xmlns:nhib="urn:nhibernate-configuration-2.2">
...
<nhib:hibernate-configuration>
<nhib:session-factory>
<nhib:property name="show_sql" xdt:Locator="Match(name)" xdt:Transform="SetAttributes">false</nhib:property>
</nhib:session-factory>
</nhib:hibernate-configuration>