@@ -54,12 +54,7 @@ internal enum DynamoDBConsumer
5454 internal bool IsEmptyStringValueEnabled { get { return Config . IsEmptyStringValueEnabled ; } }
5555 internal IEnumerable < string > StoreAsEpoch { get { return Config . AttributesToStoreAsEpoch ; } }
5656 internal IEnumerable < string > KeyNames { get { return Keys . Keys ; } }
57-
58- #if NETSTANDARD
59- internal AmazonDynamoDBClient DDBClient { get ; private set ; }
60- #else
6157 internal IAmazonDynamoDB DDBClient { get ; private set ; }
62- #endif
6358
6459 #endregion
6560
@@ -366,7 +361,19 @@ private TableDescription DescribeTable(string tableName)
366361 } ;
367362 this . AddRequestHandler ( req , isAsync : false ) ;
368363
369- var info = this . DDBClient . DescribeTable ( req ) ;
364+ #if NETSTANDARD
365+ // Cast the IAmazonDynamoDB to the concrete client instead, so we can access the internal sync-over-async methods
366+ var client = DDBClient as AmazonDynamoDBClient ;
367+ if ( client == null )
368+ {
369+ throw new InvalidOperationException ( "Calling the synchronous LoadTable from .NET or .NET Core requires initializing the Table " +
370+ "with an actual AmazonDynamoDBClient. You can use a mocked or substitute IAmazonDynamoDB when creating a Table via TableBuilder instead." ) ;
371+ }
372+ #else
373+ var client = DDBClient ;
374+ #endif
375+
376+ var info = client . DescribeTable ( req ) ;
370377
371378 if ( info . Table == null )
372379 {
@@ -413,11 +420,7 @@ internal Table(IAmazonDynamoDB ddbClient, TableConfig config)
413420 if ( ddbClient == null )
414421 throw new ArgumentNullException ( "ddbClient" ) ;
415422
416- #if NETSTANDARD
417- DDBClient = ddbClient as AmazonDynamoDBClient ;
418- #else
419423 DDBClient = ddbClient ;
420- #endif
421424 Config = config ;
422425 }
423426
@@ -938,7 +941,19 @@ internal Document PutItemHelper(Document doc, PutItemOperationConfig config)
938941 currentConfig . ConditionalExpression . ApplyExpression ( req , this ) ;
939942 }
940943
941- var resp = DDBClient . PutItem ( req ) ;
944+ #if NETSTANDARD
945+ // Cast the IAmazonDynamoDB to the concrete client instead, so we can access the internal sync-over-async methods
946+ var client = DDBClient as AmazonDynamoDBClient ;
947+ if ( client == null )
948+ {
949+ throw new InvalidOperationException ( "Calling the synchronous PutItem from .NET or .NET Core requires initializing the Table " +
950+ "with an actual AmazonDynamoDBClient. You can use a mocked or substitute IAmazonDynamoDB when creating a Table via PutItemAsync instead." ) ;
951+ }
952+ #else
953+ var client = DDBClient ;
954+ #endif
955+
956+ var resp = client . PutItem ( req ) ;
942957 doc . CommitChanges ( ) ;
943958
944959 Document ret = null ;
@@ -1013,10 +1028,22 @@ internal Document GetItemHelper(Key key, GetItemOperationConfig config)
10131028
10141029 this . AddRequestHandler ( request , isAsync : false ) ;
10151030
1031+ #if NETSTANDARD
1032+ // Cast the IAmazonDynamoDB to the concrete client instead, so we can access the internal sync-over-async methods
1033+ var client = DDBClient as AmazonDynamoDBClient ;
1034+ if ( client == null )
1035+ {
1036+ throw new InvalidOperationException ( "Calling the synchronous GetItem from .NET or .NET Core requires initializing the Table " +
1037+ "with an actual AmazonDynamoDBClient. You can use a mocked or substitute IAmazonDynamoDB when creating a Table via GetItemAsync instead." ) ;
1038+ }
1039+ #else
1040+ var client = DDBClient ;
1041+ #endif
1042+
10161043 if ( currentConfig . AttributesToGet != null )
10171044 request . AttributesToGet = currentConfig . AttributesToGet ;
10181045
1019- var result = DDBClient . GetItem ( request ) ;
1046+ var result = client . GetItem ( request ) ;
10201047 var attributeMap = result . Item ;
10211048 if ( attributeMap == null || attributeMap . Count == 0 )
10221049 return null ;
@@ -1047,7 +1074,7 @@ internal async Task<Document> GetItemHelperAsync(Key key, GetItemOperationConfig
10471074 }
10481075#endif
10491076
1050- #endregion
1077+ #endregion
10511078
10521079
10531080 #region UpdateItem
@@ -1058,7 +1085,7 @@ internal Document UpdateHelper(Document doc, Primitive hashKey, Primitive rangeK
10581085 return UpdateHelper ( doc , key , config ) ;
10591086 }
10601087
1061- #if AWS_ASYNC_API
1088+ #if AWS_ASYNC_API
10621089 internal Task < Document > UpdateHelperAsync ( Document doc , Primitive hashKey , Primitive rangeKey , UpdateItemOperationConfig config , CancellationToken cancellationToken )
10631090 {
10641091 Key key = ( hashKey != null || rangeKey != null ) ? MakeKey ( hashKey , rangeKey ) : MakeKey ( doc ) ;
@@ -1132,8 +1159,19 @@ internal Document UpdateHelper(Document doc, Key key, UpdateItemOperationConfig
11321159 req . ExpressionAttributeNames . Add ( kvp . Key , kvp . Value ) ;
11331160 }
11341161 }
1162+ #if NETSTANDARD
1163+ // Cast the IAmazonDynamoDB to the concrete client instead, so we can access the internal sync-over-async methods
1164+ var client = DDBClient as AmazonDynamoDBClient ;
1165+ if ( client == null )
1166+ {
1167+ throw new InvalidOperationException ( "Calling the synchronous UpdateItem from .NET or .NET Core requires initializing the Table " +
1168+ "with an actual AmazonDynamoDBClient. You can use a mocked or substitute IAmazonDynamoDB when creating a Table via UpdateItemAsync instead." ) ;
1169+ }
1170+ #else
1171+ var client = DDBClient ;
1172+ #endif
11351173
1136- var resp = DDBClient . UpdateItem ( req ) ;
1174+ var resp = client . UpdateItem ( req ) ;
11371175 var returnedAttributes = resp . Attributes ;
11381176 doc . CommitChanges ( ) ;
11391177
@@ -1145,7 +1183,7 @@ internal Document UpdateHelper(Document doc, Key key, UpdateItemOperationConfig
11451183 return ret ;
11461184 }
11471185
1148- #if AWS_ASYNC_API
1186+ #if AWS_ASYNC_API
11491187 internal async Task < Document > UpdateHelperAsync ( Document doc , Key key , UpdateItemOperationConfig config , CancellationToken cancellationToken )
11501188 {
11511189 var currentConfig = config ?? new UpdateItemOperationConfig ( ) ;
@@ -1275,7 +1313,19 @@ internal Document DeleteHelper(Key key, DeleteItemOperationConfig config)
12751313 currentConfig . ConditionalExpression . ApplyExpression ( req , this ) ;
12761314 }
12771315
1278- var attributes = DDBClient . DeleteItem ( req ) . Attributes ;
1316+ #if NETSTANDARD
1317+ // Cast the IAmazonDynamoDB to the concrete client instead, so we can access the internal sync-over-async methods
1318+ var client = DDBClient as AmazonDynamoDBClient ;
1319+ if ( client == null )
1320+ {
1321+ throw new InvalidOperationException ( "Calling the synchronous DeleteItem from .NET or .NET Core requires initializing the Table " +
1322+ "with an actual AmazonDynamoDBClient. You can use a mocked or substitute IAmazonDynamoDB when calling DeleteItemAsync instead." ) ;
1323+ }
1324+ #else
1325+ var client = DDBClient ;
1326+ #endif
1327+
1328+ var attributes = client . DeleteItem ( req ) . Attributes ;
12791329
12801330 Document ret = null ;
12811331 if ( currentConfig . ReturnValues == ReturnValues . AllOldAttributes )
0 commit comments