Coding, content and startups

James Crowley

web.config transformations for NHibernate

with 2 comments

If you’re trying to use web.config transformations in VS 2010 with nHibernate you might be hitting the same issue I’ve been getting the transformation to match the hibernate-configuration node. The reason is because you have to specify an xmlns="urn:nhibernate-configuration-2.2" attribute as part of the configuration:

<configuration>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.connection_string">connection string</property>
      ...
    </session-factory>
  </hibernate-configuration>
</configuration>

To fix, just set the namespace on the target node in the transformation file like this:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
               xmlns:hib="urn:nhibernate-configuration-2.2">
  <hib:hibernate-configuration>
    <hib:session-factory>
      <hib:property xdt:Transform="Replace" xdt:Locator="Match(name)" name="connection.connection_string">your connection string</hib:property>
    </hib:session-factory>
  </hib:hibernate-configuration>
</configuration>

Written by james.crowley

January 19th, 2011 at 12:22 pm

Posted in Coding,NHibernate

2 Responses to 'web.config transformations for NHibernate'

Subscribe to comments with RSS or TrackBack to 'web.config transformations for NHibernate'.

  1. Thank you for your post.But I perfer using the XML file XD.

    http://

    21 Jan 11 at 1:41 am

  2. [...] assigned to it. I've had hit and miss success using this method and found a more reliable solution here. In short, add the namespace to your transformation file and use it when "finding" the target node. [...]

Leave a Reply