title: Cascade issue when deleting an entity in a one-to-one relationship using Fluent NHibernate
body: <p>I have the following db tables which I have simplified for this example:</p>
  
  <p><strong>Webpage</strong> Id, URLIdentifier</p>
  
  <p><strong>WebpageMetaData</strong> Webpage_id Keywords</p>
  
  <p>Webpage_id is the primary key for the table and a foriegn key back to the webpage table.</p>
  
  <p>I am then using Fluent NHibernate and its automapping feature to map these to the following POCO classes:</p>
  
  <pre><code>public class Webpage
  {
      public virtual int Id { get; set; }
      public virtual string UrlIdentifier { get; set; }
      public virtual WebpageMetaData WebpageMetaData { get; set; }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public class WebpageMetaData
  {
      public virtual int Id { get; set; }
      public virtual string Keywords{ get; set; }
      public virtual Webpage Webpage { get; set; }
  </code></pre>
  
  <p>}</p>
  
  <p>I want to map these entities as one-to-one, so I override the automapping as follows:</p>
  
  <pre><code>public class WebpageMap : IAutoMappingOverride&lt;Webpage&gt;
  {        
      public void Override(AutoMapping&lt;Webpage&gt; mapping)
      {
          mapping.HasOne(w =&gt; w.WebpageMetaData)
              .Not.Constrained()
              .Fetch.Join()
              .Cascade.All();
      }
  }
  
  public class WebpageMetaDataMap : IAutoMappingOverride&lt;WebpageMetaData&gt;
  {
      public void Override(AutoMapping&lt;WebpageMetaData&gt; mapping)
      {
          mapping.Id(w =&gt; w.Id, "Webpage_id").GeneratedBy.Foreign("Webpage");
  
          mapping.HasOne(w =&gt; w.Webpage)
              .ForeignKey("Webpage_id")
              .Constrained()
              .Fetch.Join()
              .Cascade.None();
      }
  }
  </code></pre>
  
  <p>I have tested these mappings and cascade rules and they work for selecting, inserting and updating.  However when i perform a delete of the WebpageMetaData I get an exception saying that</p>
  
  <p>"deleted object would be re-saved by cascade (remove deleted object from associations)[WebpageMetaData#524]"</p>
  
  <p>The only way to stop the exception is by doing the following before saving:</p>
  
  <pre><code>webpageMetaData.Webpage.WebpageMetaData = null;
  </code></pre>
  
  <p>So I have to set a null reference to myself from my parent??!  This seems wrong?  have I got my mapping wrong?</p>
  
  <p>Thanks.</p>
  
  <p><strong>Update 1:</strong>
  Please see the NH mappings that FLuent is producing, in case this is of help to the hard core NHibernator's :)</p>
  
  <pre><code>&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true"&gt;
    &lt;class xmlns="urn:nhibernate-mapping-2.2" name="EveryPage.Core.Domain.Webpage, EveryPage.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Webpage`"&gt;
      &lt;id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" unsaved-value="0"&gt;
        &lt;column name="Id" /&gt;
        &lt;generator class="identity" /&gt;
      &lt;/id&gt;
      &lt;one-to-one cascade="all" class="EveryPage.Core.Domain.WebpageMetaData, EveryPage.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" constrained="false" fetch="join" name="WebpageMetaData" /&gt;
      &lt;property name="UrlIdentifier" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
        &lt;column name="UrlIdentifier" /&gt;
      &lt;/property&gt;    
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  
  
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true"&gt;
    &lt;class xmlns="urn:nhibernate-mapping-2.2" name="EveryPage.Core.Domain.WebpageMetaData, EveryPage.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`WebpageMetaData`"&gt;
      &lt;id name="Id" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" unsaved-value="0"&gt;
        &lt;column name="Webpage_id" /&gt;
        &lt;generator class="foreign"&gt;
          &lt;param name="property"&gt;Webpage&lt;/param&gt;
        &lt;/generator&gt;
      &lt;/id&gt;
      &lt;one-to-one cascade="none" class="EveryPage.Core.Domain.Webpage, EveryPage.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" constrained="true" fetch="join" foreign-key="Webpage_id" name="Webpage" /&gt;
      &lt;property name="Keywords" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
        &lt;column name="Keywords" /&gt;
      &lt;/property&gt;
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>