Summary
- I'm trying to learn how to read and write to Azure Cloud Table Storage.
- I've read a number of tutorials, and have some questions.
- In the following simple code example, we access a storage account, get a reference to an existing table, insert a record, and then read the record back from the table, noting that it now exists within the cloud storage table.
Simple Code Example
static void Main(string[] args)
{
try
{
CloudStorageAccount storageAccount =
CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=<your_storage_name>;AccountKey=<your_account_key>");
CloudTableClient tableClient = storageAccount.CreateCloudTableClient();
CloudTable table = tableClient.GetTableReference("people");
table.CreateIfNotExists();
CustomerEntity customer1 = new CustomerEntity("Harp", "Walter");
customer1.Email = "[email protected]";
customer1.PhoneNumber = "425-555-0101";
// Create the TableOperation that inserts the customer entity.
var insertOperation = TableOperation.Insert(customer1);
// Execute the insert operation.
table.Execute(insertOperation);
// Read storage
TableQuery<CustomerEntity> query =
new TableQuery<CustomerEntity>()
.Where(TableQuery.GenerateFilterCondition("PartitionKey",
QueryComparisons.Equal, "Harp"));
var list = table.ExecuteQuery(query).ToList();
}
catch (StorageException ex)
{
// Exception handling here.
}
}
public class CustomerEntity : TableEntity
{
public string Email { get; set; }
public string PhoneNumber { get; set; }
public CustomerEntity(string lastName, string firstName)
{
PartitionKey = lastName;
RowKey = firstName;
}
public CustomerEntity() { }
}
Questions
- Is a table the same as a blob or a container?
- If I wanted to setup my "people" table on my Azure Cloud Storage Account, before actually performing any code operations, do I just create a new storage account, and then create a container or a blob? I can't see any option to create a "table" on the Azure management website?
- Once the table exists, do I have to create columns to represent the properties of my entity object that I'm trying to store within the table? Or does the table simply automatically take its structure from the structure of my entity object and its properties?