至Azure Storage Account下特定容器後
移動至Tables
去做新增並指定Table name
移至
儲存體瀏覽器 (預覽)
我們還能查看剛的資料
在更深入一層Portal操作點進去看
可以進行"新增實體"
再新增一個 多一個不同的property
所以可看到schema可動態新增
也不被侷限schema pre-defined
要刪除也可以複選操作
在此進行C# API端操作
添加
nuget安裝
Azure.Data.Tables
connection string 也是從access key去複製過來的(比照blob前幾篇介紹)
using Azure.Data.Tables;
string connStr = ".....core.windows.net";
string tableName = "Orders";
AddEntity("01", "Mobile", 100);
AddEntity("02", "Laptop", 80);
AddEntity("03", "Desktop", 90);
AddEntity("04", "Laptop", 200);
void AddEntity(string orderID, string category, int quantity)
{
TableClient tableClient = new TableClient(connStr, tableName);
TableEntity entity = new TableEntity(category, orderID)
{
{"quantity", quantity}
};
tableClient.AddEntity(entity);
Console.WriteLine("Added Entity with order ID :{0}", orderID);
}
讀取
using Azure;
using Azure.Data.Tables;
string connStr = "DefaultEndpointsProtocol=https;AccountName=sastg1;AccountKey=KUe+phizs0k+5fzT6KhhtL5nVOHCKIAUtXe+jsJurGzoB+Qka8xHxOHf4lhFjjKOM79drnFFsQLx+AStAm8Yeg==;EndpointSuffix=core.windows.net";
string tableName = "Orders";
//AddEntity("01", "Mobile", 100);
//AddEntity("02", "Laptop", 80);
//AddEntity("03", "Desktop", 90);
//AddEntity("04", "Laptop", 200);
QueryEntity("Laptop");
void AddEntity(string orderID, string category, int quantity)
{
TableClient tableClient = new TableClient(connStr, tableName);
TableEntity entity = new TableEntity(category, orderID)
{
{"quantity", quantity}
};
tableClient.AddEntity(entity);
Console.WriteLine("Added Entity with order ID :{0}", orderID);
}
void QueryEntity(string category)
{
TableClient tableClient = new TableClient(connStr, tableName);
Pageable<TableEntity> results = tableClient.Query<TableEntity>(entity => entity.PartitionKey == category);
foreach(TableEntity tableEntity in results)
{
Console.WriteLine("Order Id : {0}", tableEntity.RowKey);
Console.WriteLine("Quantity : {0}",tableEntity.GetInt32("quantity"));
}
}
刪除
using Azure;
using Azure.Data.Tables;
string connStr = "DefaultEndpointsProtocol=https;AccountName=sastg1;AccountKey=KUe+phizs0k+5fzT6KhhtL5nVOHCKIAUtXe+jsJurGzoB+Qka8xHxOHf4lhFjjKOM79drnFFsQLx+AStAm8Yeg==;EndpointSuffix=core.windows.net";
string tableName = "Orders";
//AddEntity("01", "Mobile", 100);
//AddEntity("02", "Laptop", 80);
//AddEntity("03", "Desktop", 90);
//AddEntity("04", "Laptop", 200);
Console.WriteLine("before Delete");
QueryEntity("Laptop");
Console.WriteLine("after Delete");
DeleteEntity("Laptop", "04");
QueryEntity("Laptop");
void AddEntity(string orderID, string category, int quantity)
{
TableClient tableClient = new TableClient(connStr, tableName);
TableEntity entity = new TableEntity(category, orderID)
{
{"quantity", quantity}
};
tableClient.AddEntity(entity);
Console.WriteLine("Added Entity with order ID :{0}", orderID);
}
void QueryEntity(string category)
{
TableClient tableClient = new TableClient(connStr, tableName);
Pageable<TableEntity> results = tableClient.Query<TableEntity>(entity => entity.PartitionKey == category);
foreach(TableEntity tableEntity in results)
{
Console.WriteLine("Order Id : {0}", tableEntity.RowKey);
Console.WriteLine("Quantity : {0}",tableEntity.GetInt32("quantity"));
}
}
void DeleteEntity(string category,string orderID)
{
TableClient tableClient = new TableClient(connStr, tableName);
tableClient.DeleteEntity(category, orderID);
Console.WriteLine("entity is deleted!!");
}