title: Fluent NHibernate Has Many to Many Convention Questions
body: <p>I am new to fluent nhibernate and nhibernate.  I want to write a fluent nhibernate autopersistence convention to handle creating the many to many mappings for my entities.</p>
  
  <p>This is what I have right now:</p>
  
  <pre><code>using System;
  using FluentNHibernate.Conventions;
  using FluentNHibernate.Mapping;
  
  namespace Namespace
  {
      public class HasManyToManyConvention : IHasManyToManyConvention
      {
          public bool Accept(IManyToManyPart target) {
              return true;
          }
  
          public void Apply(IManyToManyPart target) {
              var parentName = target.EntityType.Name;
              var childName = target.ChildType.Name;
              const string tableNameFmt = "{0}To{1}";
              const string keyColumnFmt = "{0}Fk";
              string tableName;
  
              if (parentName.CompareTo(childName) &lt; 0) {
                  tableName = String.Format(tableNameFmt, parentName, childName);
              }
              else {
                  tableName = String.Format(tableNameFmt, childName, parentName);
              }
  
              target.WithChildKeyColumn(String.Format(keyColumnFmt, childName));
              target.WithParentKeyColumn(String.Format(keyColumnFmt, parentName));
              target.WithTableName(tableName);
              target.Cascade.All();
          }
      }
  }
  </code></pre>
  
  <p>It seems to work,  but I feel that there is a better way to do this.</p>
  
  <p>Now my questions:</p>
  
  <ol>
  <li>Do you have a better way to do this?</li>
  <li>Do you usually want the Cascade behavior here?</li>
  <li>Do I need to worry about something besides making sure both sides of this association end up with the same table name?</li>
  </ol>