1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ITableEntity の一部のプロパティを無視する方法

Posted at

ITableEntity の一部のプロパティを無視する方法

# 以下の記事が書かれた時の版数は .NET Core 3.1 (3.1.24)、Azure.Data.Tables 12.5.0 となります.

Microsoft.Azure.Cosmos.Table の時にはエンティティの一部のプロパティを無視するための Microsoft.Azure.Cosmos.Table.IgnorePropertyAttribute クラスが存在しました. Azure.Data.Tables になって一見無視するための手段がなくなってしまったように見えますが、標準で存在する System.Runtime.Serialization.IgnoreDataMemberAttribute クラスが使えるようになっています.

以下、使用例.

using Azure;
using Azure.Data.Tables;
using System;
using System.Runtime.Serialization;

namespace WebApplication1.Models
{
    public sealed class BillingSummary : ITableEntity
    {
        [IgnoreDataMember]
        public string SubscriptionId { get; set; }
        public int BillingAmount { get; set; }
        public bool IsFinalized { get; set; }
        [IgnoreDataMember]
        public DateTime YearMonth { get; set; }

        public string PartitionKey { get => SubscriptionId; set => SubscriptionId = value; }
        public string RowKey { get => $"{YearMonth:yyyyMM}"; set => YearMonth = DateTime.ParseExact(value, "yyyyMM", null); }
        public DateTimeOffset? Timestamp { get; set; }
        public ETag ETag { get; set; }
    }
}

情報源は Azure.Data.TablesCHANGELOG です. 12.2.0-beta.1 (2021-08-10) で機能追加されたようです.

cf: [FEATURE REQ] Allow specific properties to be ignored on ITableEntity implementation #19782

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?