I am a C# .net developer and I am creating an email tracking system. I want to store my data to the Azure Table Storage, but I want to create all the entities in the same partition with different row key. My properties key are same but the value is different. For example:
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"
Now I want to create a copy of above, but with different rowKey value, same Partition key-value and same property key but with different value. Like this:
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"
Here is the C# code that I am using to add the properties:
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));
}
}
Any help would be appreciated.
Your code of inserting entity worked for me. Just to keep it simple, as you know the data type:
foreach (KeyValuePair<string, string> keyValuePair in list)
{
if (keyValuePair.Key.Equals("subject"))
{
dynamicTableEntity.Properties.Add("subject", EntityProperty.GeneratePropertyForString(keyValuePair.Value));
}
...
}
As you didn't mention what exception you get, I assume there's a RowKey conflict when the row keys get the same value in one second as "SSS" used in DateTime has no effect. Try using fff
or FFF
to get milliseconds .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.