0
votes

I have an azure table that contains 2 different entities

These 2 entity have the same partition key, it is intentional by design so these entities are

stored in one partition.

Row key is of course unique.

Is it possible to query only a specific entity by partition key?

or do i have to manualy create a property as an identifier for each entity in the same azure table?

basically the shape of my table is

Partition Key| Row Key  |Entity Type |
====================================
1            |  X       | Entity A
1            |  Y       | Entity B
1            |  Z       | Entity B

I only want to retrieve for Entity B using the Partition Key 1

2
I'm not pretty sure what you mean by query only a specific entity by partition key. As you mentioned these 2 entities has different row key then you can specify the row key and partition key to retrieve the one you want. Might be better provide more information.Shaun Xu
Sorry i didnt put enough details, I updated the question, there are multiple rows for the entity that i want to retrieve that is why i cant retrieve by PK and RK because it will only return 1 rowreggieboyYEAH
If you can leverage some existing properties then you can query based on them, but if not, I think you have to add a property.Shaun Xu
You can retrieve only the specific properties you want as well (which may likely give you an approximation of retrieving your specific type). Search for "Query a subset of entity properties" in the same page URL I gave you.Heath

2 Answers

1
votes

Specify both the partition key and the row key to retrieve a single entity. See http://www.windowsazure.com/en-us/documentation/articles/storage-dotnet-how-to-use-table-storage-20/#retrieve-single-entity for example code.

1
votes

To query a specific entity you need to supply both the partition and the row key.

If you query only on the partition key, you get all rows with that partition key.

In your example above, querying using the partition key and 'Entity Type' will be less efficient than querying on the partition key and the row key. If the partition is large, the query can be quite slow since a partition scan will be needed.