So I started to wonder if it was possible to create class that implements ITableEntity and offer the dynamic features of an ExpandoObject. After a bit of hacking around in LinqPad I have this solution.
In this snippet I also implemented the ICustomMemberProvider which is part of the LinqPad extensions API for queries (more on this here). In Visual Studio we'll need to remove that code.
Please note that you need to use the dynamic keyword to be able to define properties dynamically. You can also use the entity indexer like I did with the LastName property.
Result
List<ElasticTableEntity> (1 item)
PartitionKey
RowKey
Timestamp
ETag
FirstName
Number
Bool
Date
TokenId
LastName
Partition123
2520391787589766073
2013-03-13 1:00:40 AM +00:00
W/"datetime'2013-03-13T01%3A00%3A40.619873Z'"
Pascal
34
False
1912-03-04 12:00:00 AM +00:00
50604c02-f01c-48fc-862e-7ea66153f434
Laurin
Result with projection
List<ElasticTableEntity> (1 item)
PartitionKey
RowKey
Timestamp
ETag
Date
FirstName
Partition123
2520391787589766073
2013-03-13 1:00:40 AM +00:00
W/"datetime'2013-03-13T01%3A00%3A40.619873Z'"
1912-03-04 12:00:00 AM +00:00
Pascal
The ElasticTableEntity allows us to define properties at run time which will be added to the table when inserting the entities. Tables in the Azure Table Storage have flexible schema so we are free to store entities with different properties as long a we respect some limitations:
Entities can have no more than 252 different properties (that's for the Table)
An Entity's data can be up to 1 MB in size
A property must be one of the following types : byte[], bool, DateTime, double, Guid, int, long or string
A property value can be up to 64 KB in size (for string and byte array)
A property name is case sensitive and can be no more than 255 characters in length
You can store about any kind of data as long as it is one of the supported data type. You could also encode other kind of date type in a byte array or a string (like a json document). Just be careful to always stick to one data type for a property (yes, we can store like int, bool and string in the same column using different entities!)