skip to Main Content

  • Is there a difference between TableEntity and DynamicTableEntity?

  • I read articles but still don’t understand the relevance: Azure.Data.Tables v12 doesn’t have a class DynamicTableEntity under Azure.Data.Tables.

  • Is there any equivalent class that I can use for the same for the migration?

2

Answers


  1. I am facing the same issue with my code. While reading the Microsoft docs, I found this description of the TableEntity type. The Azure.Data.Tables TableEntity class is:

    A generic dictionary-like ITableEntity type which defines an arbitrary set of properties on an entity as key-value pairs.

    This appears to be the replacement for DynamicTableEntity. Furthermore, it implements:

    ITableEntity, ICollection<KeyValuePair<String,Object>>, ICollection<KeyValuePair<TKey,TValue>>, IDictionary<String,Object>, IEnumerable<KeyValuePair<String,Object>>, IEnumerable<KeyValuePair<TKey,TValue>>, IEnumerable, IEnumerable

    Also, it has type conversion helper methods that can be used in place of the former EntityProperty helper methods.

    https://learn.microsoft.com/en-us/dotnet/api/azure.data.tables.tableentity?view=azure-dotnet

    Login or Signup to reply.
  2. For anyone hitting this later. Here is an example of property updates in the
    Azure.Data.Table world.

            public async Task<bool> UpdateField<V>(string partitionKey, string rowKey, string fieldName, V entityProperty)
            {
                var dynamicEntity = new TableEntity
                {
                    PartitionKey = partitionKey,
                    RowKey = rowKey
                };
                dynamicEntity.Add(fieldName, entityProperty);
                var result = await TableClient.UpdateEntityAsync<TableEntity>(dynamicEntity, ETag.All, TableUpdateMode.Merge);
                if (result == null || result.IsError) return false;
                return true;
        }
    

    Note the ETag.All, this will simply blanket update the specified field regardless. Explore other options if you need to check the version of the record you are updating etc. Also note, V used for generic value in this instance as it is a part of a generic class that uses T already.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search