title: Fluent NHibernate Mapping for Table in multiple Many-to-Many Relationships
body: <p>I'am trying to set Fluent NHibernate mappings for the Database shown below:</p>
  
  <pre><code> Campaign Table
   Id
   Name
  
  Category Table
  Id  
  Campaign_id
  Name
  
  Customer Table
  Id
  Name
  Phone
  ...
  
  SalesMan Table
  Id
  Name
  Phone
  ...
  
  CustomerSalesManCategory Table
  Id
  Customer_id
  SalesMan_id
  Category_id
  </code></pre>
  
  <p>The CustomerSalesManCategory table's columns has as foreignKeys the Primary Keys of Customer,SalesMan,Category respectively.</p>
  
  <p>A Campaign has a one to many relationship with Category</p>
  
  <p>A Customer has a many to many relationship with Category</p>
  
  <p>A Customer has a many to many relationship with SalesMan  but also is related with the Category</p>
  
  <p>That is:A customer is assigned a SalesMan for a specific Category and as a result a correct entry in the CustomerSalesManCategory Table should perfectly reflect that(all 3 id's populated)</p>
  
  <p>With the mapping i currently have,entries are inserted in the CustomerSalesManCategory with NULLS on SalesMan_id or Category_id-which is correct for the mappings I provided.</p>
  
  <p>However,i cant figure out the mappigns for having FluentNhibernate do the job correctly done..Single entrty in CustomerSalesManCategory table on SaveOrUpdate for Customer.</p>
  
  <p>Any help is very much appriciated.
  Here are my current Mappings:</p>
  
  <pre><code> public class CampaignMap : ClassMap&lt;Campaign&gt;
  {
      public CampaignMap()
      {
          Id(x =&gt; x.Id);
          Map(x =&gt; x.Name);
          Map(x =&gt; x.CreationDate);
          HasMany(x =&gt; x.CampaignsCategories).Inverse().Cascade.AllDeleteOrphan();
      }
  }
  
    public class CategoryMap : ClassMap&lt;Category&gt;
  {
      public CategoryMap()
      {
         Id(x =&gt; x.Id);
         Map(x =&gt; x.Extension);
         References(x =&gt; x.Campaign);
         HasManyToMany(x =&gt;         x.CustomersAssginedInCategory).Inverse().Table("CustomerSalesManCategory");           
      } 
  }
  
  public class CustomerMap : ClassMap&lt;Customer&gt;
  {
      public CustomerMap()
      {
          Id(x =&gt; x.Id);
          Map(x =&gt; x.CallingName);
          Map(x =&gt; x.OfficialName);
          Map(x =&gt; x.Year);
          Map(x =&gt; x.Description);
          HasManyToMany(x =&gt; x.CustomerCategories).Table("CustomerSalesManCategory");
          HasManyToMany(x =&gt; x.CustomerSalesMen).Table("CustomerSalesManCategory");
      }
  }
  
   public class SalesManMap : ClassMap&lt;SalesMan&gt;
  {
      public SalesManMap()
      {
          Id(x =&gt; x.Id);
         Map(x =&gt; x.Name);
         Map(x =&gt; x.Email);
         Map(x =&gt; x.Phone);
         Map(x =&gt; x.Description);
         HasManyToMany(x =&gt; x.CustomersAssignedTo).Inverse().Table("CustomerSalesManCategory");           
      }
  }  
  </code></pre>