Whenever learning new technologies I like to write the simplest possible example. Usually this means a console app with the least number of references. I've been trying, with little success, to write an app that reads and writes to Azure table storage. I've used this how-to guide as a basis, but try to do everything in the Main method. Similar approach worked well with the blob storage, but the table storage is giving trouble.
I was able to create a table with this code.
static void Main(string[] args)
{
Microsoft.WindowsAzure.Storage.Table.CloudTableClient tableClient =
new Microsoft.WindowsAzure.Storage.Table.CloudTableClient(
new Uri("http://mystorage.table.core.windows.net/"),
new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("[somename]", "[somekey]"));
CloudTable table = tableClient.GetTableReference("people");
table.CreateIfNotExists();
}
After running this code I could see a table in my storage using Azure Storage Explorer. (Still haven't figured out how to see the table in manage.windowsazure.com.)
However, if I try to insert records (as described in the how-to guide mentioned before), I get a conflict 409 EntityAlreadyExists. Azure Storage Explorer doesn't show any records in my table.
CustomerEntity customer1 = new CustomerEntity("Harp", "Walter");
customer1.Email = "[email protected]";
customer1.PhoneNumber = "425-555-0101";
TableOperation insertOperation = TableOperation.Insert(customer1);
table.Execute(insertOperation);
Also, I'm baffled by the two overlapping namespaces. Both Microsoft.WindowsAzure.Storage.Table and Microsoft.WindowsAzure.StorageClient contain e.g. a CloudTableClient class. Why are there two client namespaces and which one am I supposed to use?
EDIT Turns out the record does exist. Simply double-clicking the table in Azure Table Explorer doesn't show the table contents. You have to click Query. The last question still stands. Why the two namespaces?