use*_*610 32 azure-table-storage
我正在使用Azure表存储来存储数据.我对何时使用insert-or-replace和insert-or-merge感到困惑.我正在使用Azure SDK 1.7.
我对插入或替换的理解是,如果实体存在,则用新实体替换先前实体的整个属性.如果新实体未定义属性或属性值为null,则在更新时将删除该属性.
在插入或合并中,即使新实体未在新实体中定义新属性,也将保留旧属性.我的理解是否正确?
Mahender
Geo*_*ell 26
是! 你的理解是正确的.
您可以通过运行下面用正确的C#代码测试connectionString和tableName:
class MyEntity : TableEntity
{
public string MyString { get; set; }
}
class MySecondEntity : TableEntity
{
public string MySecondString { get; set; }
}
public void MergeTest()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference(tableName);
table.CreateIfNotExists();
// Insert an entity
table.Execute(TableOperation.Insert(new MyEntity()
{ PartitionKey = "partition", RowKey = "row", MyString = "randomString" }));
// Merge with a different class
table.Execute(TableOperation.InsertOrMerge(new MySecondEntity()
{ PartitionKey = "partition", RowKey = "row", MySecondString = "randomSecondString" }));
}
Run Code Online (Sandbox Code Playgroud)
您最终应该在表中使用以下属性的单个实体:
{
PartitionKey = "partition",
RowKey = "row",
MyString = "randomString",
MySecondString = "randomSecondString"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10631 次 |
| 最近记录: |