1

I am trying to retrieve some entities from a table. I am successfully able to get back strings but when I try to get GUID, it comes back empty (all zeros).

[DataContract]
public class myEntity : TableEntity
{
    [DataMember(Name = "ID")]
    public Guid Id { get; set; }

    [DataMember(Name = "Name")]
    public string Name { get; set; }

    [DataMember(Name = "City")]
    public string City { get; set; }

}

...

var storageAccount = CloudStorageAccount.Parse(conStr);
var tableClient = storageAccount.CreateCloudTableClient();
var table = tableClient.GetTableReference(tblName);
TableQuery<myEntity> query = new TableQuery<myEntity>().Where(string.Empty);

How do I get the correct value of GUIDs in table storage? Is it related to TableEntity.ReadEntity?

Rotem Varon
  • 1,597
  • 1
  • 15
  • 32

2 Answers2

4

I don't think there is any extra operation required to get GUID properties. Have you cross checked by other tools if there is indeed values stored in GUID propeties of that table?

Zhaoxing Lu
  • 6,319
  • 18
  • 41
  • thanks for the follow up and yes, i did. I used Azure management studio and I can see valid GUIDs in that column – Rotem Varon Jul 18 '16 at 05:00
  • from looking at the table with Azure Management studio, I see the type is GUID. Any thoughts? – Rotem Varon Jul 18 '16 at 20:07
  • Could you try DynamicTableEntity type? It stores the properties in a dictionary. If you could put the dictionary value here, I can provide more help. – Zhaoxing Lu Jul 19 '16 at 01:33
  • OK, your last comment helped solve it in a differnt way. I am still unsure why the strongly typed way did not work but results achieved and I am out of time here. I used: var entities = table.ExecuteQuery(new TableQuery()).ToList(); and entities[i].Properties.TryGetValue("ID", out ep); and ep?.GuidValue.ToString(). Works! – Rotem Varon Jul 19 '16 at 18:12
  • The root cause is clear. Your property name in the strong type class is "Id", but actually the GUID is stored in Azure Storage as "ID". Property names in Azure Storage Table are case sensitive. – Zhaoxing Lu Jul 20 '16 at 00:59
  • unfortunately, I do not share the same clarity with you as I tried with all cases and it still did not get me the result I was looking for. Thanks for your insights. – Rotem Varon Jul 20 '16 at 17:21
1

@RotemVaron, you can use the function TableEntity.ReadEntity Method (IDictionary<String, EntityProperty>, OperationContext) to deserializes the entity using the specified IDictionary<TKey, TValue> that maps property names to typed EntityProperty values. Then, getting the Guid value from the EntityProperty object.

There is a blog shows the sample Reading existing entities which traverse the properties include GuidValue from entity.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43