//Init
var role = new No2verse.AzureTable.Base.AzureTableRole("TEST1", new No2verse.AzureTable.AzureStorageSettings
{
//Azure Table Connection String.
//DefaultEndpointsProtocol=https;AccountName=azureblobname;AccountKey=....
ConnectionString = AzureConnectionString
});
//Create Table
//needToCheckExisted for check table existed and create .
var operatorMain = new No2verse.AzureTable.Collections.Operator(role, "tablesample1", true);
3. 新增修改資料,請注意你的物件必須要繼承 DTableEntity ,這樣就變得很簡單
//UpdateData
var data1 = new User
{
PartitionKey = "PART1",
RowKey = "DONMA",
Birth = new DateTime(1983, 6, 21),
Name = "DONMA HSU",
CarInfo = new User.Car { BuyDate = DateTime.Now, Color = "RED", No = 123456, Name = "SWIFT" }
};
operatorMain.Update(data1);
4. 刪除資料
//Delete Data
operatorMain.Delete("PART1", "DONMA");
5.查詢單筆資料
//Get Data
var queryMain = new No2verse.AzureTable.Collections.Query(role, "tablesample1");
var data=queryMain.DataByPRKey("PART1", "DONMA");
Console.WriteLine(JsonConvert.SerializeObject(data));
6.使用 PartitionKey 取得所有資料
//GetAllData By PartitionKey
var data2 = queryMain.DatasByPartitionKey("PART1");
Console.WriteLine(JsonConvert.SerializeObject(data2));
using No2verse.AzureTable.Collections;
namespace No2verse.AzureTable.Base
{
///
///
///
public interface IAzureTableOperator
{
string TableName { get; }
bool IsAutoGCOnDtor { get; set; }
AzureTableRole Role { get; }
bool Delete(string partitionKey, string rowKey);
bool DeleteByPK(string partitionKey);
bool DeleteByRK(string rowKey);
string Insert(DTableEntity data);
bool IsDataExist(string partitionKey, string rowKey);
Operator Update(DTableEntity data);
Operator UpdateWithEtag(DTableEntity data);
bool DeleteWithEtag(string partitionKey, string rowKey, string eTag);
}
}
using System.Collections.Generic;
namespace No2verse.AzureTable.Base
{
///
///
///
///
public interface IAzureTableQuery
{
string TableName { get; }
bool IsAutoGCOnDtor { get; set; }
AzureTableRole Role { get; }
IEnumerable All();
string[] AllPartitionKeys();
string[] AllRowKeysByPartitionKey(string partitionKey);
T[] AllDatas();
List AllDatasList();
T DataByPRKey(string partitionKey, string rowKey);
List DatasByPartitionKey(string partitionKey);
List DatasByRowKey(string rowKey);
int DataCount();
int DataCountByPartitionKey(string partitionKey);
List DataListByKeys(params PRPair[] prpairs);
bool IsDataExist(string partitionKey, string rowKey);
}
}
至於第七點如何加速,我有一些其他想法之後我再來寫文章分享一下
--
Before you read this, the article was in a superposition of human and AI. Upon observation, the wave function collapsed into a sleep-deprived developer.