Exemplo n.º 1
0
        private static void DeleteExampleAdapter()
        {
            DataTable table = new DataTable();

            table.Columns.Add("PartitionKey");
            table.Columns.Add("RowKey");
            table.Columns.Add("MyField");

            DataRow row = table.NewRow();

            row["PartitionKey"] = "MyPartitionKey";
            row["RowKey"]       = "RowKey2";
            row["MyField"]      = "Some Data";

            table.Rows.Add(row);
            table.AcceptChanges();

            row.Delete();

            DbProviderFactory factory = DbProviderFactories.GetFactory("Magurany.Data.TableStorageClient");

            using (DbConnection connection = factory.CreateConnection())
            {
                connection.ConnectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");
                connection.Open();

                DbCommand deleteCommand = connection.CreateCommand("DELETE /MyTable(PartitionKey=@PartitionKey,RowKey=@RowKey)");
                deleteCommand.AddMappedParameter("PartitionKey", DbType.String, "PartitionKey");
                deleteCommand.AddMappedParameter("RowKey", DbType.String, "RowKey");

                DbDataAdapter adapter = factory.CreateDataAdapter();
                adapter.DeleteCommand = deleteCommand;
                adapter.Update(table);
            }
        }