Azure Table Storage supports only basic data types like (int, string, Guid, DateTime) etc. This makes it hard to store objects which themselves contain objects inside them i.e. nested objects. It is also not supported to directly store List<> and other such collection data types.
For this, I created a CustomEntity class which inherits from ITableEntity and implemented the ReadEntity and WriteEntity methods using the newly introduced TableEntity.Flatten(...) and TableEntity.ConvertBack<TResult>(...) methods. I am for now only focusing on storing nested objects.
public class CustomEntity : ITableEntity
{
// Partition Key, Row Key, Timestamp and ETag here
public void ReadEntity(IDictionary<string, EntityProperty> properties, OperationContext operationContext)
{
CustomEntity customEntity = TableEntity.ConvertBack<CustomEntity>(properties, operationContext);
// Do the memberwise clone for this object from the returned CustomEntity object
CloneThisObject(this, customEntity);
}
public IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
{
IDictionary<string, EntityProperty> flattenedProperties = TableEntity.Flatten(this, operationContext);
flattenedProperties.Remove("PartitionKey");
flattenedProperties.Remove("RowKey");
flattenedProperties.Remove("Timestamp");
flattenedProperties.Remove("ETag");
return flattenedProperties;
}
}
I used the above code in my model and was able to successfully insert a nested object in the Azure tables. The issue comes when I want to retrieve the same object. The code gets stuck in an infinite loop at the table.Execute(TableOperation.Retrieve(partitionKey, rowKey)) command.
Also, while the WriteEntity code was hit during insert operation of the CustomEntity object, the ReadEntity code isn't hit while retrieving the entity. What am I missing here? Any help would be greatly appreciated.