title: Fluent NHibernate: how to map the where clause filter on a ManyToMany
body: <p>I'm having an issue with persisting a field which is in my were clause on a ManyToMany releationship, but doesn't explicityly exist on the class mapping. Hard to explain but its the "is_expred" field in the below classes and mappings.</p>
  
  <p>I have the following two classes:</p>
  
  <pre><code>public class Publication
  {
      public virtual int Id {get; set;}
  
      public virtual string Name {get; set;}
  }
  
  public class Role
  {
      public virtual int Id {get; set;}
      public virtual string Name {get; set;}
  
      public virtual IEnumerable&lt;Publication&gt; CurrentPublications {get; set;}
  
      public virtual IEnumerable&lt;Publication&gt; ExpiredPublications {get; set;}
  }
  </code></pre>
  
  <p>Where a publication can exist in either or both the CurrentPublications and ExpiredPublications. (and no, I can't put the expired field on the Publication, as its only expired for this particular role - it might be current on a different role)</p>
  
  <p>The DB for this is:</p>
  
  <pre><code>role
  {
      role_id     int (PK)
      role_name   varchar(50)
  }
  
  role_pub
  {
      role_id     int (PK)
      pub_id      int (PK)
      is_expired  bit
  }
  
  pub
  {
      pub_id      int (PK)
      pub_name    varchar(50)
  }
  </code></pre>
  
  <p>And the fluent mapping:</p>
  
  <pre><code>public class RoleMapping : ClassMap&lt;Role&gt;
  {
      public RoleMapping()
      {
          Table("role");
          Id(x =&gt; x.Id, "role_id").GeneratedBy.Identity();
          Map(x =&gt; x.Name, "role_name").Not.Nullable();
  
          HasManyToMany&lt;Publication&gt;(x =&gt; x.CurrentPublications)
              .Table("role_pub")
              .ParentKeyColumn("role_id")
              .ChildKeyColumn("pub_id")
              .Where("is_expired = 0")
              .LazyLoad();
  
          HasManyToMany&lt;Publication&gt;(x =&gt; x.ExpiredPublications)
              .Table("role_pub")
              .ParentKeyColumn("role_id")
              .ChildKeyColumn("pub_id")
              .Where("is_expired = 1")
              .LazyLoad();
      }
  }
  
  
  public class PublicationMapping : ClassMap&lt;Publication&gt;
  {
      public PublicationMapping()
      {
          Table("pub");
          Id(x =&gt; x.Id, "pub_id").GeneratedBy.Identity();
          Map(x =&gt; x.Name, "pub_name").Not.Nullable();
      }
  }
  </code></pre>
  
  <p>When I do the select on a role, the Current and Expired Publications are populated with the correct Publications, but when I add new publciations to either Current or Expired lists, it always saves the is_expired field as 0, which is the default value of "is_expired" in the DB.</p>
  
  <p>Does anyone have any idea on wha tthe correct way of mapping this releationship and populating the "is_expired" field correctly?</p>
  
  <p>Thanks for your help</p>
  
  <p>Saan</p>