第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 C# 在 Azure 表存儲中自動生成 RowKey

如何使用 C# 在 Azure 表存儲中自動生成 RowKey

C#
拉丁的傳說 2021-11-21 10:40:01
我正在嘗試從 Micorosft Docs 教程中的預定義姓氏更改 RowKey:https ://docs.microsoft.com/en-us/azure/cosmos-db/table-storage-how-to-use-dotnet#add -an-entity-to-a-table,為唯一值。這是我當前的代碼:private void storeuserinput(Activity activity)        {            var uid = activity.From.Id;            var uname = activity.From.Name;            if (activity.Text?.ToLower().ToString() == "no" || activity.Text?.ToLower().ToString() == "NO" || activity.Text?.ToLower().ToString() == "No" || activity.Text?.ToLower().ToString() == "Nope" || activity.Text?.ToLower().ToString() == "nope")            {                var userinput = firstmessage;                string connectionString = CloudConfigurationManager.GetSetting("StorageConnectionString");                // Parse the connection string and return a reference to the storage account.                CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));                // Create the table client.                CloudTableClient tableClient = storageAccount.CreateCloudTableClient();                // Retrieve a reference to the table.                CloudTable table = tableClient.GetTableReference("UnansweredChatBot");                // Create the table if it doesn't exist.                table.CreateIfNotExists();                // Create a new customer entity.                CustomerEntity customer1 = new CustomerEntity("NoSolution", "Smith");                customer1.Query = firstmessage;                // Create the TableOperation object that inserts the customer entity.                TableOperation insertOperation = TableOperation.Insert(customer1);                // Execute the insert operation.                table.Execute(insertOperation);            }            //extract other data from "activity" object            //your code logic here            //store data in your table storage            //Note: specifcial scenario of user send attachment        }
查看完整描述

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 中。


這就是你要找的東西嗎?


查看完整回答
反對 回復 2021-11-21
  • 1 回答
  • 0 關注
  • 227 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號