簡體   English   中英

Azure表存儲(Partition key row key),如何在同一個partition不同rowKey對應插入多個實體?

[英]Azure table storage (Partition key row key), how to insert multiple entities in corresponding to same parttion and different rowKey?

我是一名 C# .net 開發人員,我正在創建一個電子郵件跟蹤系統。 我想將我的數據存儲到 Azure 表存儲,但我想使用不同的行鍵在同一分區中創建所有實體。 我的屬性鍵相同,但值不同。 例如:

partition key = "Test+id"
row key=123
properties:
subject:"Hello",
from:"xyz@gmail.com",
to:"abc@gmail.com",
body:"Hello I am a test email"

現在我想創建上面的副本,但具有不同的 rowKey 值、相同的 Partition 鍵值和相同的屬性鍵但具有不同的值。 像這樣:

partition key = "Test+id",
row key="787",
properties:
subject: "HelloTesting",
from:"sam@gmail.com",
to:"alex@gmail.com",
body: "Hello I am a test email2, this is so nice"

這是我用來添加屬性的 C# 代碼:

foreach (KeyValuePair<string, string> keyValuePair in list)
{
    dynamicTableEntity.RowKey = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.SSS");
    Console.WriteLine(keyValuePair.Key);

    if (keyValuePair.Key.Equals("subject"))
    {
        dynamicTableEntity.Properties.Add("subject", EntityProperty.CreateEntityPropertyFromObject(keyValuePair.Value));
    }
    else if (keyValuePair.Key.Equals("toRecipients") )
    {
        dynamicTableEntity.Properties.Add("toRecipients", EntityProperty.CreateEntityPropertyFromObject(keyValuePair.Value));
    }
    else if (keyValuePair.Key.Equals("from") )
    {
        dynamicTableEntity.Properties.Add("from", EntityProperty.CreateEntityPropertyFromObject(keyValuePair.Value));
    }
    else if (keyValuePair.Key.Equals("bodyPreview") )
    {
        dynamicTableEntity.Properties.Add("bodyPreview", EntityProperty.CreateEntityPropertyFromObject(keyValuePair.Value));
    }
    else
    {
        dynamicTableEntity.Properties.Add(keyValuePair.Key, EntityProperty.CreateEntityPropertyFromObject(keyValuePair.Value));
    }
}

任何幫助,將不勝感激。

您插入實體的代碼對我有用。 只是為了簡單起見,因為您知道數據類型:

foreach (KeyValuePair<string, string> keyValuePair in list)
{
    if (keyValuePair.Key.Equals("subject"))
    {
        dynamicTableEntity.Properties.Add("subject", EntityProperty.GeneratePropertyForString(keyValuePair.Value));
    }

    ...
}

由於你沒有提到你得到了什么異常,我假設當行鍵在一秒內獲得相同的值時存在RowKey沖突,因為 DateTime 中使用的“SSS”無效。 嘗試使用fffFFF來獲取毫秒

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM