title: How to Delete in a many to many relationship?
body: <p>I have a many to many relationship:</p>
  
  <blockquote>
    <p>Product has many Categories and Category has Many Products.</p>
  </blockquote>
  
  <p>Say I have</p>
  
  <pre><code>Shopping Category  
  Food Category
  
  Product A - Shopping Category, Food Category  
  Product B - Shopping Category
  </code></pre>
  
  <p>Now I delete <code>Shopping Category</code>. I want the <code>Product A</code> reference to be removed from <code>Shopping Category</code> and I want <code>Product B</code> to be removed completely.</p>
  
  <p>I would end up with:</p>
  
  <pre><code>Product A - Food Category.
  </code></pre>
  
  <p>How do I do this in nhibernate (I am using fluent nhibernate).</p>
  
  <p>I tried to use Cascade <code>DeleteOrphan</code> and <code>AllDeleteOrphan</code> but when I do that and delete Shopping both Product A and B get deleted.</p>
  
  <pre><code>public class CategoryMapping : ClassMap&lt;Category&gt;
  {
      public CategoryMapping()
      {
          Id(x =&gt; x.Id).GeneratedBy.GuidComb();
  
          Map(x =&gt; x.Name).Not.Nullable().NvarcharWithMaxSize();
          HasManyToMany(x =&gt; x.Products).Cascade.DeleteOrphan();
      }
  }
  
  
  public class ProductMapping : ClassMap&lt;Product&gt;
  {
      public ProductMapping()
      {
          Id(x =&gt; x.Id).GeneratedBy.GuidComb();
          Map(x =&gt; x.Name).Not.Nullable().NvarcharWithMaxSize();
          HasManyToMany(x =&gt; x.Categories);
      }
  }
  
    unitOfWork.BeginTransaction();
    Category category =session.Load&lt;Category&gt;(id);
    session.Delete(category);
    unitOfWork.Commit();
  </code></pre>