在C#中填充Azure表存储表

问题描述 投票:0回答:1

我正在尝试找到一种很好的方法来使用C#一次填充Azure表存储的表。现在,我正在使用CloudTable.CreateIfNotExistAsync()创建启动时所需的表。我的意思是我可以检查所需的初始条目是否已经存在,是否可以创建它们,但是也许有更聪明的方法可以执行。也许C#SDK有一些我还不认识的机制。

c# azure azure-table-storage populate
1个回答
2
投票

我是说我可以检查我需要的初始条目是否已经在里面如果不创建它们,但也许有更聪明的方法可以做到。也许C#SDK有一些我还不认识的机制。

对于您的情况,我建议对实体执行InsertOrReplace操作,如果实体不存在,它将创建一个实体,如果存在则将其替换。

InsertOrReplace

其他选择可能是尝试创建一个实体并捕获var account = CloudStorageAccount.Parse("UseDevelopmentStorage=true");// new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true); var tableClient = account.CreateCloudTableClient(); var table = tableClient.GetTableReference("Customer"); table.CreateIfNotExists(); var entity = new DynamicTableEntity("partitionkey", "rowkey"); entity.Properties.Add("key", new EntityProperty("value")); var operation = TableOperation.InsertOrReplace(entity); var result = await table.ExecuteAsync(operation); ,如果该实体已经存在,它将被抛出。

© www.soinside.com 2019 - 2024. All rights reserved.