Azure / azure-cosmos-table-dotnet

.NET SDK for Azure Cosmos Table API
14 stars 6 forks source link

Object is always read as string #74

Open DannyvanderKraan opened 3 years ago

DannyvanderKraan commented 3 years ago

Package: <PackageReference Include="Azure.Data.Tables" Version="12.0.0-beta.8" />

I have the following entity:

public class PropertyInfoEntryTableEntity : ITableEntity
    {
        public PropertyInfoEntryTableEntity()
        {
            //Obligated empty default constructor
        }

        public string BatchId { get; set; }
        public string PartitionKey { get; set; }
        public string RowKey { get; set; }
        public DateTimeOffset? Timestamp { get; set; }
        public ETag ETag { get; set; }

        public object PropertyInfoValue { get; set; }

        public string PropertyInfoKey { get; set; }

        public static string CreatePartitionKey(string unitId)
        {
            return unitId;
        }

        public static string CreateRowKey(long timeStampAsReversedTicks)
        {
            return timeStampAsReversedTicks.ToString();
        }

    }

As you can see PropertyInfoValue is of type object.

I initialize the entity like so:

var entity = new PropertyInfoEntryTableEntity()
            {
                BatchId = Guid.NewGuid().ToString(),
                PartitionKey = partitionKey,
                PropertyInfoKey = "key3",
                PropertyInfoValue = DateTime.UtcNow,
                RowKey = rowkey,
            };

Notice that PropertyInfoValue is a DateTime. When I insert this item via AddEntityAsync in the TableClient I can see in Azure Portal the entity is inserted as expected.

But when I retrieve the entity via GetEntityAsync in the TableClient then PropertyInfoValue's value has become of type System.String (tested by writing PropertyInfoValue.GetType() to console). The string value however is how you expected nicely formatted with ISO standard: "2021-06-04T14:55:30.9772495Z"

Boolean, Int, Double, etc. all work as expected.

I expected as with CosmosDb SQL API SDK that the Table API SDK would notice it's a datetime string and would Deserialize it back to a proper DateTime?