[英]Fluent NHibernate Relation Without Foreign Key
我正在嘗試這樣簡化我的問題,但基本上我正在嘗試映射2個實體但是我沒有數據庫集中的外鍵,因為列可能為null。 當我嘗試在父項上插入時,我收到以下錯誤:
object引用未保存的瞬態實例 - 在刷新之前保存瞬態實例,或者將屬性的級聯操作設置為使其自動保存的內容。
這是我到目前為止:
我的實體
public class DocumentDraft
{
public virtual Guid Id { get; set; }
public virtual string Subject { get; set; }
public virtual string ReferenceNo { get; set;}
public virtual DocumentType DocumentType { get; set; }
}
public class DocumentType
{
public virtual short Id { get; set; }
public virtual string Description { get; set; }
}
制圖
public class DocumentDraftMap : ClassMap<DocumentDraft>
{
public DocumentDraft()
{
// other mappings ...
References(x => x.DocumentType)
.Columns("DocumentTypeId")
.Nullable()
.Not.LazyLoad()
.NotFound.Ignore(); // <-- added this since the value could be null and it throws an error
}
}
我嘗試在映射中指定Cascade.None()
,但我得到了相同的結果。 基本上會發生的事情是嘗試插入DocumentType
中的null
值,我不想這樣(我想在父表中插入null,但我根本不想觸及子表,我不想這個級聯)。
我也試過: .Not.Insert()
,但這也不起作用。
如果有人可以幫我解決這個問題,我會很感激。
我想保存時屬性DocumentType不是真的null。 似乎有一個實例並且沒有Cascade.All()在引用上它無法保存。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.