I'm trying to establish a One-to-One relationship (Two-sided References relationship) between two classes. Both Properties should not be nullable. The problem is whe开发者_如何转开发n you try to save one first over the other, I encounter the Null or Transient value error.
class A
{
C C {get;set;}
}
class C
{
A A {get;set;}
}
class AMapping : ClassMap<A>
{
AMapping()
{
References(x=>x.C)
.Not.Nullable();
}
}
class CMapping : ClassMap<C>
{
CMapping()
{
References(x=>x.A)
.Not.Nullable();
}
}
I understand that since NHibernate can't make a reference to an object that doesn't exist (in the databaase) yet, but would there be a pattern or a feature that I can use to circumvent this limitation?
Try setting cascade="none" on one side of the Many-To-One mapping. Something like:
References(x=>x.C)
.Not.Nullable()
.Cascade.None();
精彩评论