I am just learning Azure Table Storage and I'm able to save and retrieve entities without any problem. However, I'd like to do the following. Say I have row keys (all with the same partition key) that look as follows:
KJV-C1-V1
KJV-C1-V2
KJV-C1-V3
KJV-C2-V1
KJV-C2-V2
KJV-C2-V3
I'd like to be able to perform two types of queries in .NET C#:
Preferrably I'd like to be able to do this without reading all entities in the partition and filtering the ones that don't match the pattern I'm looking for. Is this possible with Azure Table Storage queries?
答案 0 :(得分:5)
Retrieve all entities with row keys that start with 'KJV-C1'.
This is possible. Sample OData query:
PartitionKey eq 'your partition key' and (RowKey ge 'KJV-C1' and RowKey lt 'KJV-C2')
Retrieve all entities with row keys that contain '-C1-' in the key
This unfortunately is not possible. You would have to fetch all entities and filter the data on the client side.
答案 1 :(得分:1)
你不能在键上做像contains()这样的事情。但由于它支持CompareTo("")方法,因此您需要稍微修改表格设计。
维护多个分区键而不是单个键。你可以简单地推动KJV'行键的一部分到分区键。然后从C1-V1开始,C1-V2作为行键。
然后,如果你想要
或者表格中的设计更改,您需要遍历您的主要产品,例如KJV'并构建多个查询,每个查询以' KJV-C1 - '开头,然后联合所有查询以获得最终结果。
请注意,表存储不允许所有LINQ操作,有时您需要设计表键以记住大多数查询。