我有一个名为ProjectTaskBudget
type 的类IBudgetableIncomeStream
,如下所示:
public class ProjectTaskBudget
{
public virtual IBudgetableIncomeStream BudgetableIncomeStream { get; set; }
}
IBudgetableIncomeStream
是一个接口,除其他外,它应用于一个名为的抽象类Deliverable
:
public abstract class Deliverable : IBudgetableIncomeStream
{
// Some stuff
}
和一个名为的具体类RecurringIncomeLine
:
public class RecurringIncomeLine : IBudgetableIncomeStream
{
// Some stuff
}
继承自的具体类Deliverable
是DeliverableItem
和DeliverableTime
。
的映射ProjectTaskBudget
如下所示:
public class ProjectTaskBudgetMap : MappingBase<ProjectTaskBudget>
{
public ProjectTaskBudgetMap()
{
ReferencesAny(n => n.BudgetableIncomeStream)
.EntityTypeColumn("IncomeStreamType")
.EntityIdentifierColumn("IncomeStream_id")
.AddMetaValue<Deliverable>("Deliverable")
.AddMetaValue<RecurringIncomeLine>("RecurringIncomeLine")
.IdentityType<Guid>();
}
}
这与 . 一样有效RecurringIncomeLine
,所以我怀疑问题与抽象/接口映射有关。当我尝试ProjectTaskBudget
使用Deliverable
, 和刷新向数据库添加新的时,我收到此错误:
NHibernate.PropertyValueException: Error dehydrating property value for xxx.xxx.xxx.ProjectTaskBudget.BudgetableIncomeStream ---> 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()
我想知道是否将接口直接应用到DeliverableItem
并DeliverableTime
会有所作为,并让映射包括
.AddMetaValue<DeliverableItem>("DeliverableItem")
.AddMetaValue<DeliverableTime>("DeliverableTime")
但这是一个相当大的重构,所以我想先检查一下,看看我是否遗漏了更明显的东西,或者这听起来像是无稽之谈。