title: Combine Fluent and XML mapping for NHibnernate
body: <p>I just fell in love with NHibernate and the fluent interface. The latter enables very nice mappings with refactoring support (no more need for xml files).</p>
  
  <p>But nobody is perfect, so I am missing the many-to-any mapping in fluent. Does anybody know if it is already there? If so, a simple line of code would be nice.</p>
  
  <p>But to stick to the header of the question, is there any way to combine fluent and normal NHibernate mapping. </p>
  
  <p>Currently I use the following lines for my test setup WITH fluent, and the second code block for my test WITHOUT fluent (with XML mappings). How can I tell fluent to use fluent IF AVAILABLE and XML otherwise...</p>
  
  <pre><code>        var cfg = new Configuration();
          cfg.AddProperties(MsSqlConfiguration.MsSql2005.ConnectionString.Is(_testConnectionstring).ToProperties());
          cfg.AddMappingsFromAssembly(typeof(CatMap).Assembly);
          new SchemaExport(cfg).Create(true, true);
  
          var persistenceModel = new PersistenceModel();
          persistenceModel.addMappingsFromAssembly(typeof(CatMap).Assembly);
          IDictionary&lt;string, string&gt; properties = MsSqlConfiguration.MsSql2005.UseOuterJoin().ShowSql().ConnectionString.Is(_testConnectionstring).ToProperties();
          properties.Add("command_timeout", "340");
  
          session = new SessionSource(properties, persistenceModel).CreateSession();
  </code></pre>
  
  <p>Without Fluent...</p>
  
  <pre><code>        config = new Configuration();
          IDictionary props = new Hashtable();
  
          props["connection.provider"] = "NHibernate.Connection.DriverConnectionProvider";
          props["dialect"] = "NHibernate.Dialect.MsSql2005Dialect";
          props["connection.driver_class"] = "NHibernate.Driver.SqlClientDriver";
          props["connection.connection_string"] = "Server=localhost;initial catalog=Debug;Integrated Security=SSPI";
          props["show_sql"] = "true";
          foreach (DictionaryEntry de in props)
          {
              config.SetProperty(de.Key.ToString(), de.Value.ToString());
          }
          config.AddAssembly(typeof(CatMap).Assembly);
  
          SchemaExport se = new SchemaExport(config);
          se.Create(true, true);
  
          factory = config.BuildSessionFactory();
          session = factory.OpenSession();
  </code></pre>
  
  <p>That's it...
  Chris</p>
  
  <p>PS: I really like this site, the GUI is perfect, and the quality of all articles is incredible. I think it will be huge :-) Have to register...</p>