zoukankan      html  css  js  c++  java
  • Writing DynamicTableEntity to Azure Storage Table

    There are ample of samples available to show how to insert an object/entity to Azure Storage Table. However, all the samples inherit from TableEntity

    This sample shows how to insert custom entities to table when we don’t have a class that inherits from TableEntity.

     

    void Main()
    {
        var account = "";
        var key = "";
        var tableName = "";
    
        var storageAccount = GetStorageAccount(account, key);
        var cloudTableClient = storageAccount.CreateCloudTableClient();
        var table = cloudTableClient.GetTableReference(tableName);
        
        var partitionKey = "pk";
        var rowKey = "rk";
        
        //create the entity
        var entity = new DynamicTableEntity(partitionKey, rowKey, "*", 
            new Dictionary<string,EntityProperty>{
                    {"Prop1", new EntityProperty("stringVal")},
                    {"Prop2", new EntityProperty(DateTimeOffset.UtcNow)},
                });
        
        //save the entity
        table.Execute(TableOperation.InsertOrReplace(entity));
        
        //retrieve the entity
        table.Execute(TableOperation.Retrieve(partitionKey,rowKey)).Result.Dump();
    }
    
    static CloudStorageAccount GetStorageAccount(string accountName, string key, bool useHttps = true)
    {
        var storageCredentials = new StorageCredentials(accountName, key);
        var storageAccount = new CloudStorageAccount(storageCredentials, useHttps: useHttps);
        return storageAccount;
    }

    This code makes use of DynamicTableEntity which can take properties and values as IDictionary.

  • 相关阅读:
    在Unix上使用管道压缩exp导出文件
    自制CPU的黑暗历程一
    Error C1189: #error: Please use the /MD switch for _AFXDLL builds
    Redis乐观锁解决高并发抢红包的问题
    PHP分页类
    汇编基础——使用nasm和bochs学习汇编
    数据同步工具DBsync
    完成端口的一些教程
    sdf
    (转)C#(WIN FORM)两个窗体间LISTVIEW值的修改
  • 原文地址:https://www.cnblogs.com/dupeng0811/p/writing-dynamictableentity-to-azure-storage-table.html
Copyright © 2011-2022 走看看