1 回答

TA貢獻1828條經驗 獲得超4個贊
在您的客戶實體類中,您正在調用構造函數
public CustomerEntity(string lastName, string firstName)
{
this.PartitionKey = lastName;
this.RowKey = firstName;
}
因此,當您初始化一個新對象時,您會傳遞兩個參數(如構造函數中定義的)firstname和lastname.
新的
這些是由構造函數按名稱設置的,并且在它們的上下文之外(即在表存儲中)沒有任何意義。
CustomerEntity customer1 = new CustomerEntity("NoSolution", "Smith");
在您的代碼中,您需要做的就是將構造函數更改為
public CustomerEntity(string requesterName, string uniqueRowKey)
{
this.PartitionKey = requesterName ;
this.RowKey = uniqueRowKey;
}
您的 RowKey 必須是唯一的,并且您的分區(qū)鍵用于通過對相似類型的行進行分組來使搜索更容易。然后你可以像這樣傳遞給你的構造函數:
string rowKey = Guid.NewGuid().ToString("N"); //This give you a unique guid with no hyphens.
CustomerEntity customer1 = new CustomerEntity("John Smith", rowKey);
這將分別將您的實體插入到 Partition Key 和 Row Key 中。
這就是你要找的東西嗎?
- 1 回答
- 0 關注
- 227 瀏覽
添加回答
舉報