1
votes

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:"[email protected]",
to:"[email protected]",
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:"[email protected]",
to:"[email protected]",
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.

1
Hi, welcome! Where are the code that you use to add in Azure Table? Can you provide more information?Rogerson Nazário
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(myStorageConnectionString); CloudTableClient tableClient = storageAccount.CreateCloudTableClient(); CloudTable table = tableClient.GetTableReference("MailCheckerSystem"); await table.CreateIfNotExistsAsync(); // To insert var tableOperation = TableOperation.Insert(dynamicTableEntity); await table.ExecuteAsync(tableOperation);yogita chauhan
What exception did you get? Though you might have resolved it as of now, it can help others.Deepak

1 Answers

0
votes

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.