Storing data in Azure Table Services via TableServiceEntity you're limited to usual basic types (int, string, datetime etc) that have public get/set.
There is none of the usual magic you've come to expect from serialization that deals with collections, complex types, inheritance etc.
Different ways of dealing with this could be
Have I missed anything? Which method may be best in which circumstances?
Inheritance is supported by the ATS. All inherited properties in the realized concrete class will be persisted and retrieved. However, complex types are indeed not supported.
There is at least one more way of dealing with the persistence of object trees and object relationships: Store related objects separately under a different PartitionKey/RowKey.
Simplest (brute force) way to implement that approach may require that you make multiple calls to ATS, so that you can deserialize objects properly.
If the number of transactions performed against storage is more important than the storage space and bandwidth used, a more elegant extension of that approach would be to implement interfaces for your entities and create a "wide" Union entity that implements all those interfaces - and that's the guy that is stored and retrieved. Each Union object that is retrieved is utilized through particular interface only. You can store collections as well as simply related entities this way - simply make sure your PartitionKey is the same for everyone who is related to the Union object and you have a way of identifying which Union object represents which entity type.
HTH
I'm not sure if this answers your question, but if you need to upload complex types you could just serialize the data into a Byte Array.
I needed to upload a List of KeyValuePair's to TableStorage so I simply used a binary formatter to serialize it to a byte array, then deserialize and cast it back when retrieving it.
Serialize:
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, keyValuePairList);
byte[] ba = ms.ToArray();
Deserialize and cast back:
MemoryStream ms = new MemoryStream(byteArray);
BinaryFormatter bf = new BinaryFormatter();
var obj = bf.Deserialize(ms);
//cast object back to List of KeyValuePair
var keyValuePairList = (List< KeyValuePair<string,string> >)obj;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With