DynamicTableEntity
IDictionary<string,EntityProperty>
作为参数。
此代码执行于LinqPad
:
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;
}