Skip to content

Commit 53df097

Browse files
David EllingsworthDavid Ellingsworth
authored andcommitted
Implement async version of isDirty for OneToOneType.
1 parent 6b34fc9 commit 53df097

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/NHibernate/Async/Type/OneToOneType.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,29 @@ public override async Task NullSafeSetAsync(DbCommand cmd, object value, int ind
4646
.NullSafeSetAsync(cmd, await (GetReferenceValueAsync(value, session, cancellationToken)).ConfigureAwait(false), index, session, cancellationToken)).ConfigureAwait(false);
4747
}
4848

49-
public override Task<bool> IsDirtyAsync(object old, object current, ISessionImplementor session, CancellationToken cancellationToken)
49+
public override async Task<bool> IsDirtyAsync(object old, object current, ISessionImplementor session, CancellationToken cancellationToken)
5050
{
51-
if (cancellationToken.IsCancellationRequested)
51+
cancellationToken.ThrowIfCancellationRequested();
52+
if (IsSame(old, current))
5253
{
53-
return Task.FromCanceled<bool>(cancellationToken);
54+
return false;
5455
}
55-
try
56+
57+
if (old == null || current == null)
5658
{
57-
return Task.FromResult<bool>(IsDirty(old, current, session));
59+
return true;
5860
}
59-
catch (Exception ex)
61+
62+
if ((await (ForeignKeys.IsTransientFastAsync(GetAssociatedEntityName(), current, session, cancellationToken)).ConfigureAwait(false)).GetValueOrDefault())
6063
{
61-
return Task.FromException<bool>(ex);
64+
return true;
6265
}
66+
67+
object oldId = await (GetIdentifierAsync(old, session, cancellationToken)).ConfigureAwait(false);
68+
object newId = await (GetIdentifierAsync(current, session, cancellationToken)).ConfigureAwait(false);
69+
IType identifierType = GetIdentifierType(session);
70+
71+
return await (identifierType.IsDirtyAsync(oldId, newId, session, cancellationToken)).ConfigureAwait(false);
6372
}
6473

6574
public override Task<bool> IsDirtyAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken)
@@ -68,14 +77,7 @@ public override Task<bool> IsDirtyAsync(object old, object current, bool[] check
6877
{
6978
return Task.FromCanceled<bool>(cancellationToken);
7079
}
71-
try
72-
{
73-
return Task.FromResult<bool>(IsDirty(old, current, checkable, session));
74-
}
75-
catch (Exception ex)
76-
{
77-
return Task.FromException<bool>(ex);
78-
}
80+
return this.IsDirtyAsync(old, current, session, cancellationToken);
7981
}
8082

8183
public override Task<bool> IsModifiedAsync(object old, object current, bool[] checkable, ISessionImplementor session, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)