Question

I meet the same issue just like the following:

NHibernate - not-null property reference a null or transient value

And the root reason is just like what Alun Harford said: "you're saving an entire object graph, and that graph is circular". see the following code

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);
    }
}

So the relationship is bidirectional: ApplyAuthorization -(Status)-> ApplyStatus and at the same time ApplyStatus -(For)-> ApplyAuthorization.

Now I know the reason but how to handle it?

Was it helpful?

Solution

I find the root cause but don't know deeply.

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

The issue resolved if I remove the setting Not.Nullable().

But I don't know how to handle if the DBA require the Not Null constraint.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top