【问题标题】:How can I access the RowKey (and PartitionKey) when I use a input binding with a storage Table?当我将输入绑定与存储表一起使用时,如何访问 RowKey(和 PartitionKey)?
【发布时间】:2018-02-04 05:14:23
【问题描述】:

当我将输入绑定与存储表一起使用时,如何访问 RowKey(和 PartitionKey)而不出现错误“隐藏继承的成员 'TableEntity.RowKey”?

我可以很高兴地访问基于 PartitionKey 的类别,但是当我尝试通过向我的类添加新属性来扩展以获取 RowKey 时,我收到一个错误...warning CS0108: 'Person.RowKey' hides inherited member 'TableEntity.RowKey'. Use the new keyword if hiding was intended.

#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Table;
public static void Run(string myQueueItem, 
                      IQueryable<Person> tableBinding, TraceWriter log)
{
    log.Info($"C# Queue trigger:triggerblocklist processed message : [{myQueueItem}]");
    // int i = tableBinding.Count(); 
    // log.Info($"{i}");

    foreach (Person person in tableBinding.Where(p => p.PartitionKey == myQueueItem)
           .ToList())
    {
        log.Info($"RowKey:     [{person.RowKey}]");
        log.Info($"Categories: [{person.Categories}]");
    }
}
public class Person : TableEntity
{
    // public string PartitionKey { get; set; }
    public string RowKey { get; set; }  // !!!!!!!!!!!!!!!!!
    // public string Timestamp { get; set; }
    public string Categories { get; set; }
}

【问题讨论】:

  • 对为什么投反对票有任何反馈吗? ...这似乎不是一个完全愚蠢的问题,好吧,这是一个初学者的问题,但为什么要投反对票?

标签: azure azure-storage azure-functions azure-table-storage


【解决方案1】:

你继承的TableEntity 类已经有一个名为RowKey 的属性,所以.. 你的Person 类不需要定义一个名为RowKey 的属性,它已经通过它的基类拥有它。

您需要做的就是从您的Person 类中删除RowKey 属性,无需进行其他更改。

【讨论】:

  • 谢谢,现在我明白你的意思了,很高兴能正常工作
猜你喜欢
  • 1970-01-01
  • 2021-10-16
  • 2012-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-11
相关资源
最近更新 更多