Friday, October 01, 2010

Back to basics - simple Azure table test results

What happens if you try to create an object twice:

            CloudTableClient client = new CloudTableClient(
                new StorageCredentialsAccountAndKey("thing", "****blurb******"));

            var context1 = client.GetDataServiceContext();

            Thing t = new Thing();
            t.PartitionKey = "Fred";
            t.RowKey = "Bloggs";
            t.TestField = "test";

            context1.AddObject("TestData", t);
            var response = context1.SaveChanges();


            context1.AddObject("TestData", t);
            response = context1.SaveChanges();

the answer... is that you get an exception thrown in the second "SaveChanges()" - the exception is System.Data.Services.Client.DataServiceRequestException - with an InnerException of type DataServiceClientException -with StatusCode 409 - EntityAlreadyExists 

No comments:

Post a Comment