I’m trying to grasp how Azure table storage works to create facebook-style feeds and I’m stuck on how to retrieve the entries.
(My questions is almost the same as https://stackoverflow.com/questions/6843689/retrieve-multiple-type-of-entities-from-azure-table-storage but the link in the answer is broken.)
This is my intended approach:
-
Create a personal feed for all users within my application which can contain different types of entries (notification, status update etc). My idea is to store them in an Azure Table grouped by a partition key for each user.
-
Retrieve all entries within the same partition key and pass it to different views depending on entry type.
How do I query the table storage for all types of the same base type
while keeping their unique properties?
The CloudTableQuery<TElement> requires a typed entity, if I specify EntryBase as generic argument I don’t get the entry-specific properties (NotificationSpecificProperty, StatusUpdateSpecificProperty) and vice versa.
My entities:
public class EntryBase : TableServiceEntity
{
public EntryBase()
{
}
public EntryBase(string partitionKey, string rowKey)
{
this.PartitionKey = partitionKey;
this.RowKey = rowKey;
}
}
public class NotificationEntry : EntryBase
{
public string NotificationSpecificProperty { get; set; }
}
public class StatusUpdateEntry : EntryBase
{
public string StatusUpdateSpecificProperty { get; set; }
}
My query for a feed:
List<AbstractFeedEntry> entries = // how do I fetch all entries?
foreach (var item in entries)
{
if(item.GetType() == typeof(NotificationEntry)){
// handle notification
}else if(item.GetType() == typeof(StatusUpdateEntry)){
// handle status update
}
}
Finally there’s a official way! 🙂
Look at the NoSQL sample which does exactly this in this link from the Azure Storage Team Blog:
Windows Azure Storage Client Library 2.0 Tables Deep Dive