基于其他属性设置行/分区键的值

时间:2016-03-14 18:22:15

标签: azure azure-storage azure-storage-blobs

有没有办法可以覆盖TableEntity的RowKey属性的getter?

2 个答案:

答案 0 :(得分:0)

我认为可以使用 new 关键字来覆盖getter:

public class Person : TableEntity
{
    public Person(string name, string surname)
        :base(surname, name)
    {

    }

    public new string PartitionKey
    {
        get { return "OhLala" + base.PartitionKey;  }
    }

    public new string RowKey
    {
        get { return "ohMama" + base.RowKey; }
    }
}

答案 1 :(得分:0)

以下是实施ITableEntity界面的代码段

public class TestEntity : ITableEntity
{
    private string _rowKey;

    public TestEntity()
    {
        this.Properties = new Dictionary<string, EntityProperty>();
    }

    private IDictionary<string, EntityProperty> Properties { get; set; }
    public void ReadEntity(IDictionary<string, EntityProperty> properties, Microsoft.WindowsAzure.Storage.OperationContext operationContext)
    {
        this.Properties = properties;
    }
    public IDictionary<string, EntityProperty> WriteEntity(Microsoft.WindowsAzure.Storage.OperationContext operationContext)
    {
        return this.Properties;
    }
}