Skip to content

Commit b327a47

Browse files
David EllingsworthDavid Ellingsworth
David Ellingsworth
authored and
David Ellingsworth
committed
GH2552 Implement OneToOneType.IsModified based on the ManyToOneType.
1 parent 964faa7 commit b327a47

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/NHibernate/Type/OneToOneType.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,28 @@ public override bool IsDirty(object old, object current, bool[] checkable, ISess
8888

8989
public override bool IsModified(object old, object current, bool[] checkable, ISessionImplementor session)
9090
{
91-
return false;
91+
if (current == null)
92+
{
93+
return old != null;
94+
}
95+
if (old == null)
96+
{
97+
return true;
98+
}
99+
var oldIdentifier = IsIdentifier(old, session) ? old : GetIdentifier(old, session);
100+
var currentIdentifier = GetIdentifier(current, session);
101+
// the ids are fully resolved, so compare them with isDirty(), not isModified()
102+
return GetIdentifierOrUniqueKeyType(session.Factory).IsDirty(oldIdentifier, currentIdentifier, session);
103+
}
104+
105+
private bool IsIdentifier(object value, ISessionImplementor session)
106+
{
107+
var identifierType = GetIdentifierType(session);
108+
if (identifierType == null)
109+
{
110+
return false;
111+
}
112+
return value.GetType() == identifierType.ReturnedClass;
92113
}
93114

94115
public override bool IsNull(object owner, ISessionImplementor session)

0 commit comments

Comments
 (0)