@@ -123,39 +123,36 @@ public override async Task<object> HydrateAsync(DbDataReader rs, string[] names,
123
123
return identifier ;
124
124
}
125
125
126
- public override Task < object > DisassembleAsync ( object value , ISessionImplementor session , object owner , CancellationToken cancellationToken )
126
+ public override async Task < object > DisassembleAsync ( object value , ISessionImplementor session , object owner , CancellationToken cancellationToken )
127
127
{
128
- if ( cancellationToken . IsCancellationRequested )
129
- {
130
- return Task . FromCanceled < object > ( cancellationToken ) ;
131
- }
132
- try
128
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
129
+ if ( value == null )
133
130
{
134
- return Task . FromResult < object > ( Disassemble ( value , session , owner ) ) ;
131
+ return null ;
135
132
}
136
- catch ( Exception ex )
133
+
134
+ object id = await ( ForeignKeys . GetEntityIdentifierIfNotUnsavedAsync ( GetAssociatedEntityName ( ) , value , session , cancellationToken ) ) . ConfigureAwait ( false ) ;
135
+
136
+ if ( id == null )
137
137
{
138
- return Task . FromException < object > ( ex ) ;
138
+ throw new AssertionFailure ( "cannot cache a reference to an object with a null id: " + GetAssociatedEntityName ( ) ) ;
139
139
}
140
+
141
+ return await ( GetIdentifierType ( session ) . DisassembleAsync ( id , session , owner , cancellationToken ) ) . ConfigureAwait ( false ) ;
140
142
}
141
143
142
- public override Task < object > AssembleAsync ( object cached , ISessionImplementor session , object owner , CancellationToken cancellationToken )
144
+ public override async Task < object > AssembleAsync ( object cached , ISessionImplementor session , object owner , CancellationToken cancellationToken )
143
145
{
144
- if ( cancellationToken . IsCancellationRequested )
145
- {
146
- return Task . FromCanceled < object > ( cancellationToken ) ;
147
- }
148
- try
149
- {
150
- //this should be a call to resolve(), not resolveIdentifier(),
151
- //'cos it might be a property-ref, and we did not cache the
152
- //referenced value
153
- return ResolveIdentifierAsync ( session . GetContextEntityIdentifier ( owner ) , session , owner , cancellationToken ) ;
154
- }
155
- catch ( Exception ex )
146
+ cancellationToken . ThrowIfCancellationRequested ( ) ;
147
+ // the owner of the association is not the owner of the id
148
+ object id = await ( GetIdentifierType ( session ) . AssembleAsync ( cached , session , null , cancellationToken ) ) . ConfigureAwait ( false ) ;
149
+
150
+ if ( id == null )
156
151
{
157
- return Task . FromException < object > ( ex ) ;
152
+ return null ;
158
153
}
154
+
155
+ return await ( ResolveIdentifierAsync ( id , session , cancellationToken ) ) . ConfigureAwait ( false ) ;
159
156
}
160
157
}
161
158
}
0 commit comments