Ejemplo n.º 1
0
        //Does single insert of entity
        public static void DoBatchInsert()
        {
            //Parse the connection string for a storage account
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the table client.
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            // Create the table if it doesn't exist.
            CloudTable table = tableClient.GetTableReference("people");
            table.CreateIfNotExists();

            // Create a new customer entity.
            CustomerEntity customer1 = new CustomerEntity("Smith", "John");
            customer1.Email = "*****@*****.**";
            customer1.PhoneNumber = "425-555-0101";

            // Create another customer entity
            CustomerEntity customer2 = new CustomerEntity("Smith", "Ben");
            customer2.Email = "*****@*****.**";
            customer2.PhoneNumber = "425-555-0102";

            //Create Batch Operation
            //Note that batch operations must all be in the same partition
            //So in this case the last names of customer 2 and 3 have to be the same
            TableBatchOperation batchOperation = new TableBatchOperation();
            batchOperation.Insert(customer1);
            batchOperation.Insert(customer2);

            table.ExecuteBatch(batchOperation);
        }
Ejemplo n.º 2
0
        //Does single insert of entity
        public static void DoSingleInsert()
        {
            //Parse the connection string for a storage account
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting("StorageConnectionString"));

            // Create the table client.
            CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

            // Create the table if it doesn't exist.
            CloudTable table = tableClient.GetTableReference("people");
            table.CreateIfNotExists();

            // Create a new customer entity.
            CustomerEntity customer1 = new CustomerEntity("Harp", "Walter");
            customer1.Email = "*****@*****.**";
            customer1.PhoneNumber = "425-555-0101";

            TableOperation insertOperation = TableOperation.Insert(customer1);
            table.Execute(insertOperation);
        }