13
13
using System . Data . Common ;
14
14
using NHibernate . Engine ;
15
15
using NHibernate . SqlTypes ;
16
- using NHibernate . Util ;
17
16
18
17
namespace NHibernate . Type
19
18
{
20
19
using System . Threading . Tasks ;
21
20
using System . Threading ;
22
- public partial class MetaType : AbstractType , IMetaType
21
+ public partial class MetaType : AbstractType
23
22
{
24
23
25
24
public override async Task < object > NullSafeGetAsync ( DbDataReader rs , string [ ] names , ISessionImplementor session , object owner , CancellationToken cancellationToken )
26
25
{
27
26
cancellationToken . ThrowIfCancellationRequested ( ) ;
28
- object key = await ( baseType . NullSafeGetAsync ( rs , names , session , owner , cancellationToken ) ) . ConfigureAwait ( false ) ;
29
- return key == null ? null : values [ key ] ;
27
+ return GetValueForKey ( await ( _baseType . NullSafeGetAsync ( rs , names , session , owner , cancellationToken ) ) . ConfigureAwait ( false ) ) ;
30
28
}
31
29
32
- public override async Task < object > NullSafeGetAsync ( DbDataReader rs , string name , ISessionImplementor session , object owner , CancellationToken cancellationToken )
30
+ public override async Task < object > NullSafeGetAsync ( DbDataReader rs , string name , ISessionImplementor session , object owner , CancellationToken cancellationToken )
33
31
{
34
32
cancellationToken . ThrowIfCancellationRequested ( ) ;
35
- object key = await ( baseType . NullSafeGetAsync ( rs , name , session , owner , cancellationToken ) ) . ConfigureAwait ( false ) ;
36
- return key == null ? null : values [ key ] ;
33
+ return GetValueForKey ( await ( _baseType . NullSafeGetAsync ( rs , name , session , owner , cancellationToken ) ) . ConfigureAwait ( false ) ) ;
37
34
}
38
35
39
36
public override Task NullSafeSetAsync ( DbCommand st , object value , int index , bool [ ] settable , ISessionImplementor session , CancellationToken cancellationToken )
@@ -53,13 +50,25 @@ public override Task NullSafeSetAsync(DbCommand st, object value, int index, boo
53
50
}
54
51
}
55
52
56
- public override Task NullSafeSetAsync ( DbCommand st , object value , int index , ISessionImplementor session , CancellationToken cancellationToken )
53
+ public override Task NullSafeSetAsync ( DbCommand st , object value , int index , ISessionImplementor session , CancellationToken cancellationToken )
57
54
{
58
55
if ( cancellationToken . IsCancellationRequested )
59
56
{
60
57
return Task . FromCanceled < object > ( cancellationToken ) ;
61
58
}
62
- return baseType . NullSafeSetAsync ( st , value == null ? null : keys [ ( string ) value ] , index , session , cancellationToken ) ;
59
+ try
60
+ {
61
+ // "_keys?[(string) value]" is valid code provided "_keys[(string) value]" can never yield null. It is the
62
+ // case because we use a dictionary interface which throws in case of missing key, and because it is not
63
+ // possible to have a value associated to a null key since generic dictionaries do not support null keys.
64
+ var key = value == null ? null : _keys ? [ ( string ) value ] ?? value ;
65
+
66
+ return _baseType . NullSafeSetAsync ( st , key , index , session , cancellationToken ) ;
67
+ }
68
+ catch ( Exception ex )
69
+ {
70
+ return Task . FromException < object > ( ex ) ;
71
+ }
63
72
}
64
73
65
74
public override async Task < bool > IsDirtyAsync ( object old , object current , bool [ ] checkable , ISessionImplementor session , CancellationToken cancellationToken )
0 commit comments