Search code examples
azureazure-table-storageazure-storage-account

Azure Table Storage: Ignoring a property of a TableEntity when using the Azure.Data.Tables package


I am using the new Azure.Data.Tables library from Microsoft to deal with Azure Table Storage. With the old library when you had an entity that implemented ITableEntity and you had a property that you did not want to save to the storage table you would use the [IgnoreProperty] annotation. However, this does not seem to be available on the new library.

What would be the equivalent on the Azure.Data.Tables package or how do you now avoid saving a property to table storage now?

This is the class I want to persist:

public class MySpatialEntity : ITableEntity
{
    public int ObjectId { get; set; }
    public string Name { get; set; }
    public int MonitoringArea { get; set; }

    //This is the property I want to ignore because table storage cannot store it
    public Point Geometry { get; set; }

    //ITableEntity Members
    public virtual string PartitionKey { get => MonitoringArea.ToString(); set => MonitoringArea = int.Parse(value); }
    public virtual string RowKey { get => ObjectId.ToString(); set => ObjectId = int.Parse(value); }
    public DateTimeOffset? Timestamp { get; set; }
    public ETag ETag { get; set; }
}

Solution

  • As of version 12.2.0.beta.1, Azure.Data.Tables table entity models now support ignoring properties during serialization via the [IgnoreDataMember] attribute and renaming properties via the [DataMember(Name="<yourNameHere>")] attribute.

    See the changelog here.