nhibernate - 如何破解NHibernate中的 "circular reference"

标签 nhibernate reference circular-reference

我遇到了同样的问题,如下所示:

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。

现在我知道原因了,但是该如何处理呢?

最佳答案

我找到了根本原因,但了解不够深入。

References(m => m.For).Not.Nullable();

如果我删除设置 Not.Nullable(),问题就解决了。

但是我不知道如果DBA需要Not Null约束该如何处理。

关于nhibernate - 如何破解NHibernate中的 "circular reference",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20625685/

相关文章:

mysql - 使用 Qlikview/QlikSense 中的公共(public)字段处理多个事实和多个实体表 (MySQL)

mysql - 在数据库设计中如何避免循环引用?

nhibernate - 如何设置 NHibernate 事务的超时时间

c# - nhibernate 和 Entity Framework 在批处理方面有什么区别?

multithreading - 将 SharpArchitecture 的 NHibernateSession 与不同的线程结合使用

c++ - 通过引用和指针传递参数 C++

c# - 是否可以使用循环引用执行序列化?

nHibernate 复合键类类型不匹配

c++ - 谁在这里? g++ 还是 Visual Studio 2017?

excel - 如何在 VBA 中引用动态创建的控件?