diff --git a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs
index da8406801bc1..b094bbe9d8ee 100644
--- a/sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs
+++ b/sdk/src/Services/DynamoDBv2/Custom/DataModel/Configs.cs
@@ -186,8 +186,7 @@ public class DynamoDBOperationConfig
///
/// Property that directs to prefix all table names
/// with a specific string.
- /// If property is null or empty, no prefix is used and default
- /// table names are used.
+ /// If property is null, no prefix is used and default table names are used.
///
public string TableNamePrefix { get; set; }
@@ -428,9 +427,7 @@ public DynamoDBFlatConfig(DynamoDBOperationConfig operationConfig, DynamoDBConte
bool retrieveDateTimeInUtc = operationConfig.RetrieveDateTimeInUtc ?? contextConfig.RetrieveDateTimeInUtc ?? false;
bool isEmptyStringValueEnabled = operationConfig.IsEmptyStringValueEnabled ?? contextConfig.IsEmptyStringValueEnabled ?? false;
DynamoDBEntryConversion conversion = operationConfig.Conversion ?? contextConfig.Conversion ?? DynamoDBEntryConversion.CurrentConversion;
- string tableNamePrefix =
- !string.IsNullOrEmpty(operationConfig.TableNamePrefix) ? operationConfig.TableNamePrefix :
- !string.IsNullOrEmpty(contextConfig.TableNamePrefix) ? contextConfig.TableNamePrefix : string.Empty;
+ string tableNamePrefix = operationConfig.TableNamePrefix ?? contextConfig.TableNamePrefix ?? string.Empty;
// These properties can only be set at the operation level
bool disableFetchingTableMetadata = contextConfig.DisableFetchingTableMetadata ?? false;
diff --git a/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DataModelOperationSpecificConfigTests.cs b/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DataModelOperationSpecificConfigTests.cs
index 550c96a31a08..320a0bda188b 100644
--- a/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DataModelOperationSpecificConfigTests.cs
+++ b/sdk/test/Services/DynamoDBv2/UnitTests/Custom/DataModelOperationSpecificConfigTests.cs
@@ -57,6 +57,31 @@ public void BatchGetConfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void BatchGetConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(client => client.BatchGetItem(It.Is(request => request.RequestItems.ContainsKey("TableName"))))
+ .Returns(new BatchGetItemResponse { Responses = new(), UnprocessedKeys = new() })
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var batchGetConfig = new BatchGetConfig() { TableNamePrefix = "" };
+
+ var batchGet = context.CreateBatchGet(batchGetConfig);
+ batchGet.AddKey("123", "Name");
+ batchGet.Execute();
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void BatchWriteConfig()
{
@@ -90,6 +115,31 @@ public void BatchWriteConfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void BatchWriteConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(x => x.BatchWriteItem(It.Is(x => x.RequestItems.ContainsKey("TableName"))))
+ .Returns(new BatchWriteItemResponse { UnprocessedItems = new() })
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var batchWriteConfig = new BatchWriteConfig() { TableNamePrefix = "" };
+
+ var batchWrite = context.CreateBatchWrite(batchWriteConfig);
+ batchWrite.AddPutItem(new DataModel { Id = "123", Name = "Name" });
+ batchWrite.Execute();
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void TransactGetConfig()
{
@@ -123,6 +173,31 @@ public void TransactGetConfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void TransactGetConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(x => x.TransactGetItems(It.Is(x => x.TransactItems[0].Get.TableName == "TableName")))
+ .Returns(new TransactGetItemsResponse { Responses = new() })
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var transactGetConfig = new TransactGetConfig() { TableNamePrefix = "" };
+
+ var transactGet = context.CreateTransactGet(transactGetConfig);
+ transactGet.AddKey("123", "Name");
+ transactGet.Execute();
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void TransactWriteConfig()
{
@@ -156,6 +231,31 @@ public void TransactWriteConfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void TransactWriteConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(x => x.TransactWriteItems(It.Is(x => x.TransactItems[0].Update.TableName == "TableName")))
+ .Returns(new TransactWriteItemsResponse())
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var transactWriteConfig = new TransactWriteConfig { TableNamePrefix = "" };
+
+ var transactWrite = context.CreateTransactWrite(transactWriteConfig);
+ transactWrite.AddSaveItem(new DataModel { Id = "123" });
+ transactWrite.Execute();
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void QueryConfig()
{
@@ -188,6 +288,30 @@ public void QueryConfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void QueryConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(client => client.Query(It.Is(request => request.TableName == "TableName")))
+ .Returns(new QueryResponse { Items = new() })
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var queryConfig = new QueryConfig() { TableNamePrefix = "" };
+
+ var query = context.Query("123", queryConfig);
+ query.ToList();
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void FromQueryConfig()
{
@@ -225,6 +349,35 @@ public void FromQueryConfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void FromQueryConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(client => client.Query(It.Is(request => request.TableName == "TableName")))
+ .Returns(new QueryResponse { Items = new() })
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var queryOperationConfig = new QueryOperationConfig()
+ {
+ Filter = new QueryFilter("Id", QueryOperator.Equal, "123")
+ };
+
+ var fromQueryConfig = new FromQueryConfig() { TableNamePrefix = "" };
+
+ var query = context.FromQuery(queryOperationConfig, fromQueryConfig);
+ query.ToList();
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void ScanConfig()
{
@@ -257,6 +410,30 @@ public void ScanConfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void ScanConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(client => client.Scan(It.Is(request => request.TableName == "TableName")))
+ .Returns(new ScanResponse { Items = new() })
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var scanConfig = new ScanConfig() { TableNamePrefix = "" };
+
+ var scan = context.Scan(new ScanCondition[0], scanConfig);
+ scan.ToList();
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void FromScanConfig()
{
@@ -289,6 +466,30 @@ public void FromScanConfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void FromScanConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(client => client.Scan(It.Is(request => request.TableName == "TableName")))
+ .Returns(new ScanResponse { Items = new() })
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var fromScanConfig = new FromScanConfig() { TableNamePrefix = "" };
+
+ var scan = context.FromScan(new ScanOperationConfig(), fromScanConfig);
+ scan.ToList();
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void DeleteConfig()
{
@@ -320,6 +521,29 @@ public void DeleteConfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void DeleteConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(client => client.DeleteItem(It.Is(request => request.TableName == "TableName")))
+ .Returns(new DeleteItemResponse())
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var deleteConfig = new DeleteConfig() { TableNamePrefix = "" };
+
+ context.Delete("123", "Name", deleteConfig);
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void SaveConfig()
{
@@ -345,7 +569,30 @@ public void SaveConfig_OverridesTableName()
var saveConfig = new SaveConfig() { TableNamePrefix = "OperationPrefix-" };
- context.Save(new DataModel { Id = "123", Name = "Name"}, saveConfig);
+ context.Save(new DataModel { Id = "123", Name = "Name" }, saveConfig);
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
+ [TestMethod]
+ public void SaveConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(client => client.UpdateItem(It.Is(request => request.TableName == "TableName")))
+ .Returns(new UpdateItemResponse())
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var saveConfig = new SaveConfig() { TableNamePrefix = "" };
+
+ context.Save(new DataModel { Id = "123", Name = "Name" }, saveConfig);
// We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
mockClient.VerifyAll();
@@ -360,7 +607,7 @@ public void LoadConfig()
}
[TestMethod]
- public void Loadonfig_OverridesTableName()
+ public void LoadConfig_OverridesTableName()
{
var mockClient = new Mock();
mockClient.Setup(client => client.GetItem(It.Is(request => request.TableName == "OperationPrefix-TableName")))
@@ -382,6 +629,29 @@ public void Loadonfig_OverridesTableName()
mockClient.VerifyAll();
}
+ [TestMethod]
+ public void LoadConfig_RemoveTablePrefix()
+ {
+ var mockClient = new Mock();
+ mockClient.Setup(client => client.GetItem(It.Is(request => request.TableName == "TableName")))
+ .Returns(new GetItemResponse())
+ .Verifiable();
+
+ // Set a prefix on the context config, but we'll override it on the operation config so we don't expect it to be used
+ var context = new DynamoDBContext(mockClient.Object, new DynamoDBContextConfig
+ {
+ TableNamePrefix = "ContextPrefix-",
+ DisableFetchingTableMetadata = true
+ });
+
+ var loadConfig = new LoadConfig() { TableNamePrefix = "" };
+
+ context.Load("123", "Name", loadConfig);
+
+ // We expect the setup with the correct prefix to have been called, otherwise an exception would have been thrown
+ mockClient.VerifyAll();
+ }
+
[TestMethod]
public void ToDocumentConfig()
{