【发布时间】:2013-12-17 04:00:34
【问题描述】:
我遇到了同样的问题,如下所示:
NHibernate - not-null property reference a null or transient value
根本原因就像 Alun Harford 所说的那样:“您正在保存整个对象图,而该图是圆形的”。见以下代码
public class ApplyAuthorization : Activity
{
public virtual ApplyStatus Status { get; set; }
public virtual void Apply(Launch launch)
{
Status = Status ?? new ApplyStatus
{
For = this
};
Status.Update(launch);
}
}
所以关系是双向的:ApplyAuthorization -(Status)-> ApplyStatus 和同时 ApplyStatus -(For)-> ApplyAuthorization。
现在我知道原因了,但是如何处理呢?
【问题讨论】:
-
您的实体 ID 数据库是否已生成?
-
HasOne 也不行。
-
奇怪!!!无法重现问题。有效???
标签: nhibernate reference circular-reference