Azure storage and conditional substitution / merger

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;}

    //Class contains other properties which could add up to 1MB
}

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)
{
    //1. Read existing ordersInput from database
    var existingOrders = Retrieve(ordersInput.Values);

    //2. Update 'ordersInput' with existing data
    foreach(var existingOrder in existingOrders)
    {
        if(ordersInput.ContainsKey(existingOrder.RowKey)
        {
            ordersInput[existingOrder.RowKey].CreatedOn = existingOrder.CreatedOn;
            ordersInput[existingOrder.RowKey].CreatedBy = existingOrder.CreatedBy;
        }
    }

    //Save all merged orders to Azure
    SaveToAzure(existingOrders);
}

, , , 1 , API.

azure?

,

  • " ", ( ) li >

( , , concurrency)

+4
1

Azure Table Storage Upsert InsertOrReplace InsertOrMerge. InsertOrReplace , , . InsertOrMerge , , PartitionKey/RowKey , .

UPDATE

. , :

  • . . , , PartitionKey RowKey, , . .
  • . CreatedOn CreatedBy , , CreatedOn.

, . PartitionKey RowKey ( ). ordersInput , . , CreatedOn CreatedBy null , Merged. , , Inserted. .

+4

Source: https://habr.com/ru/post/1527246/


All Articles