Windows Azure Saving entity into different tables
Windows Azure Saving entity into different tables
I'm just wondering if this is reasonable thing to do. Suppose I have an entity called Message (id, creation date, user, body) and I want to store it into table storage. That's easy to do: save it and have partition key = creation date, rowkey = id (for example). Now, later in my app I want to get all messages of a user 'some_user'. If I have millions of these messages I'd extend my Save method and save the same message into 2 different tables - the one I mentioned and another one called 'messagesByUser'. So I'd set partition key = username and row key = id. Does it make sense?
But what if I later decide to have the third table I'll go and change my Save method again. But I want to follow SOLID principles and stay DRY, so the question is what pattern best suits this requirements? Anyone done something similar?
Your requirement will be addressed better if you use Sql Azure as opposed to Table storage. Table storage can have only one partition key & row key. If we query on Partition key & Row key then table storage is guaranteed to give good performance as compared to querying on other properties.
In your case, you want to query on multiple properties/columns. This would be better served by Sql Azure. In Sql Azure you can make the column on which most queries are happening as primary key and rest other as indexed columns