31
loading...
This website collects cookies to deliver better user experience
dotnet add package Azure.Data.Tables
TableClient tableClient = new TableClient(config["StorageConnection"], "Customers");
await tableClient.CreateIfNotExistsAsync();
public class CustomerEntity : ITableEntity
{
public string PartitionKey { get; set ; }
public string RowKey { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public DateTimeOffset? Timestamp { get; set; }
public ETag ETag { get; set; }
}
CustomerEntity customerEntity = new CustomerEntity()
{
PartitionKey = "Velida",
RowKey = "Will",
PhoneNumber = "0123456789",
Email = "[email protected]"
};
await tableClient.AddEntityAsync(customerEntity);
string partitionKey = "Velida";
List<CustomerEntity> familyList = new List<CustomerEntity>
{
new CustomerEntity
{
PartitionKey = partitionKey,
RowKey = "Don",
PhoneNumber = "0987612345"
},
new CustomerEntity
{
PartitionKey = partitionKey,
RowKey = "Jane",
PhoneNumber = "0987612345"
},
new CustomerEntity
{
PartitionKey = partitionKey,
RowKey = "Jan",
PhoneNumber = "0987601298",
Email = "[email protected]"
}
};
List<TableTransactionAction> addFamilyBatch = new List<TableTransactionAction>();
addFamilyBatch.AddRange(familyList.Select(f => new TableTransactionAction(TableTransactionActionType.Add, f)));
Response<IReadOnlyList<Response>> response = await tableClient.SubmitTransactionAsync(addFamilyBatch);
Pageable<TableEntity> oDataQueryEntities = tableClient.Query<TableEntity>(filter: TableClient.CreateQueryFilter($"PartitionKey eq {partitionKey}"));
foreach (TableEntity entity in oDataQueryEntities)
{
Console.WriteLine($"{entity.GetString("PartitionKey")}:{entity.GetString("RowKey")}");
}
Pageable<CustomerEntity> linqEntities = tableClient.Query<CustomerEntity>(customer => customer.RowKey == "Will");
foreach (var entity in linqEntities)
{
Console.WriteLine($"{entity.RowKey} {entity.PartitionKey}");
}
await tableClient.DeleteEntityAsync(partitionKey, "Will");