title: Fluent NHibernate - Error dehydrating property value; given key was not present in the dictionary
body: <p>I have a class called <code>ProjectTaskBudget</code> that has a property of type <code>IBudgetableIncomeStream</code>, like so:</p>
  
  <pre><code>public class ProjectTaskBudget
  {
      public virtual IBudgetableIncomeStream BudgetableIncomeStream { get; set; }
  }
  </code></pre>
  
  <p><code>IBudgetableIncomeStream</code> is an interface that's applied to, among other things, an abstract class called <code>Deliverable</code>:</p>
  
  <pre><code>public abstract class Deliverable : IBudgetableIncomeStream
  {
      // Some stuff
  }
  </code></pre>
  
  <p>and a concrete class called <code>RecurringIncomeLine</code>:</p>
  
  <pre><code>public class RecurringIncomeLine : IBudgetableIncomeStream
  {
      // Some stuff
  }
  </code></pre>
  
  <p>The concrete classes that inherit from <code>Deliverable</code> are <code>DeliverableItem</code> and <code>DeliverableTime</code>.</p>
  
  <p>The mapping for <code>ProjectTaskBudget</code> looks like this:</p>
  
  <pre><code>public class ProjectTaskBudgetMap : MappingBase&lt;ProjectTaskBudget&gt;
  {
      public ProjectTaskBudgetMap()
      {
          ReferencesAny(n =&gt; n.BudgetableIncomeStream)
              .EntityTypeColumn("IncomeStreamType")
              .EntityIdentifierColumn("IncomeStream_id")
              .AddMetaValue&lt;Deliverable&gt;("Deliverable")
              .AddMetaValue&lt;RecurringIncomeLine&gt;("RecurringIncomeLine")
              .IdentityType&lt;Guid&gt;();
      }
  }
  </code></pre>
  
  <p>This works as it should with the <code>RecurringIncomeLine</code>, so I suspect the problem is to do with the abstract/interface mapping.
  When I try to add a new <code>ProjectTaskBudget</code> to the database using a <code>Deliverable</code>, and flush, I get this error:    </p>
  
  <pre><code>NHibernate.PropertyValueException: Error dehydrating property value for xxx.xxx.xxx.ProjectTaskBudget.BudgetableIncomeStream ---&gt; System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
     at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
     at NHibernate.Type.MetaType.NullSafeSet(IDbCommand st, Object value, Int32 index, ISessionImplementor session)
     at NHibernate.Type.AnyType.NullSafeSet(IDbCommand st, Object value, Int32 index, Boolean[] settable, ISessionImplementor session)
     at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, IDbCommand statement, ISessionImplementor session, Int32 index)
     --- End of inner exception stack trace ---
     at NHibernate.Persister.Entity.AbstractEntityPersister.Dehydrate(Object id, Object[] fields, Object rowId, Boolean[] includeProperty, Boolean[][] includeColumns, Int32 table, IDbCommand statement, ISessionImplementor session, Int32 index)
     at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
     at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
     at NHibernate.Action.EntityInsertAction.Execute()
     at NHibernate.Engine.ActionQueue.Execute(IExecutable executable)
     at NHibernate.Engine.ActionQueue.ExecuteActions(IList list)
     at NHibernate.Engine.ActionQueue.ExecuteActions()
     at hiJump.Infrastructure.DataAccess.EventListeners.FixedDefaultFlushEventListener.PerformExecutions(IEventSource session) in c:\code\Git\Harmony\SharedCode\hiJump\hiJump.Infrastructure\DataAccess\EventListeners\FixedDefaultFlushEventListener.cs:line 35
     at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
     at NHibernate.Impl.SessionImpl.Flush()
  </code></pre>
  
  <p>I'm wondering if applying the interface directly to <code>DeliverableItem</code> and <code>DeliverableTime</code> would make a difference, and have the mapping include </p>
  
  <pre><code>.AddMetaValue&lt;DeliverableItem&gt;("DeliverableItem")
  .AddMetaValue&lt;DeliverableTime&gt;("DeliverableTime")
  </code></pre>
  
  <p>but that's a reasonably big refactor, so I wanted to check first and see if I was missing anything more obvious, or if that sounded like nonsense. </p>