In an Azure storage batch save operation, there is an effective way to replace certain properties for an object if it already exists; but update all properties for new objects?
Here is the script I'm talking about.
I have an object called Order
public class Order : TableEntity
{
public Order(String department, string orderId)
{
this.PartitionKey = department;
this.RowKey = orderId;
}
public DateTime CreatedOn {get; set;}
public String CreatedBy {get; set;}
public DateTime UpdatedOn {get; set;}
public String UpdatedBy {get; set;}
}
Scenario
- Azure Table Database has order objects with RowKeys [0..100]
- My API receives an upsert request for orders using RowKeys [50..150].
- In one batch transaction, I need to update certain properties on orders [50-100] and create new objects of order [101-150] on the azure image.
- Note. In existing orders [50..100], it is necessary to update all properties except CreateOn, CreatedBy, PartitionKey and RowKey.
?
( )
function Upsert(Dictionary<String, Order> ordersInput)
{
var existingOrders = Retrieve(ordersInput.Values);
foreach(var existingOrder in existingOrders)
{
if(ordersInput.ContainsKey(existingOrder.RowKey)
{
ordersInput[existingOrder.RowKey].CreatedOn = existingOrder.CreatedOn;
ordersInput[existingOrder.RowKey].CreatedBy = existingOrder.CreatedBy;
}
}
SaveToAzure(existingOrders);
}
, , , 1 , API.
azure?
,
( , , concurrency)