Is there a way to serialize collections before uploading an object to Azure Table Storage in ASP.NET 6?

Bas Hulskamp 5 Reputation points
2023-12-22T13:43:37.94+00:00

I have the following class. I want to upload an instance of this class to Azure Table Storage, but it does not support collections. I tried custom getters and setters to serialize the property, but that doesn't seem to work. Is there an attribute or another way to serialize my dictionary property as soon as I upload to Azure Table Storage?

If this feature I'm describing is not part of the package for ASP.NET yet, that would be a great addition.

public abstract class ContentBase : ITableEntity
{
    // Azure Table Storage
    public string? PartitionKey { get; set; }
    public string? RowKey { get; set; }
    public DateTimeOffset? Timestamp { get; set; }
    public ETag ETag { get; set; }

    // Custom Fields
    public string? SerializedImageURLs { get; set; }

    [IgnoreDataMember]
    public Dictionary<string, string>? ImageURLs
    {
        get
        {
            if (SerializedImageURLs == null)
                return null;

            return JsonConvert.DeserializeObject<Dictionary<string, string>>(SerializedImageURLs);
        }
        set
        {
            SerializedImageURLs = value != null ? JsonConvert.SerializeObject(value) : null;
        }
    }

}
Azure Table Storage
Azure Table Storage
An Azure service that stores structured NoSQL data in the cloud.
156 questions
{count} vote