Пример #1
0
        private static void InsertSingleEntity(string tableName)
        {
            try
            {
                //Create Table client
                CloudTableClient tableClient = storageAcc.CreateCloudTableClient();

                //Create Table
                CloudTable table = tableClient.GetTableReference(tableName);
                table.CreateIfNotExists();

                //Create a new Entity
                Employee employee1 = new Employee("1", "batman");
                employee1.LastName = "Wayne";
                employee1.FirstName = "Bruce";

                //Use a TableOperation to insert entity
                TableOperation insert = TableOperation.Insert(employee1);

                //Go ahead... Insert now...
                table.Execute(insert);

                Write(string.Format("Employee {0} inserted in {1}", employee1.RowKey, tableName));
            }
            catch (Exception ex)
            {
                Write(ex.Message);
            }
        }
Пример #2
0
        private static void InsertBatchOfEntities(string tableName)
        {
            try
            {
                //Create Table client
                CloudTableClient tableClient = storageAcc.CreateCloudTableClient();

                //Create Table
                CloudTable table = tableClient.GetTableReference(tableName);
                table.CreateIfNotExists();

                //Create a new Entity
                Employee employee1 = new Employee("1", "spiderman");
                employee1.LastName = "Parker";
                employee1.FirstName = "Peter";

                //Create a new Entity
                Employee employee2 = new Employee("1", "superman");
                employee2.LastName = "Kent";
                employee2.FirstName = "Clark";

                //Create a new Entity
                Employee employee3 = new Employee("1", "tableman");
                employee3.LastName = "Man";
                employee3.FirstName = "Table";

                //Use a TableOperation to insert entity
                TableBatchOperation batchInsert = new TableBatchOperation();
                batchInsert.Insert(employee1);
                batchInsert.Insert(employee2);
                batchInsert.Insert(employee3);

                //Go ahead... Insert now...
                table.ExecuteBatch(batchInsert);

                Write(string.Format("Employees inserted in {0}", tableName));
            }
            catch (Exception ex)
            {
                Write(ex.Message);
            }
        }