如何在条件中使用从 Azure table 检索到的行中的属性?

How to use attributes from a retrieved row from an Azure table in a conditional?

我有一个天蓝色 table,我是 populating/updating,我只想创建一个尚不存在的行,或者在缺少属性时更新该行。我在下面有我的行检查功能,但我不知道如何检查该行的属性是否为空。

纬度和经度是行属性,城市和州也是如此。

        public static async Task<bool> rowExists(CloudTable table, string city, string state)
    {
        TableOperation tOP = TableOperation.Retrieve(state, city);
        var result = await table.ExecuteAsync(tOP).ConfigureAwait(false);
        if (result.Result == null)
        {
            return false;
        }
/*          else if(row latitude or longitude == null)
        {
            return false;
        } 
*/
        else
            return true;
    }

编辑:

为了让问题更清楚,我的最终目标是插入一行不存在的行。这部分工作正常。如果该行存在,但缺少纬度或经度(比如因为达到了 API 的查询限制),我想更新该行以获取缺少的属性。

基本上解决这个问题的一种方法是将您的结果转换为 DynamicTableEntity 对象并检查那里是否存在特定的 属性。例如,您可以使用如下代码:

    public static async Task<bool> RowExists(CloudTable table, string city, string state)
    {
        TableOperation tOP = TableOperation.Retrieve(state, city);
        var result = await table.ExecuteAsync(tOP).ConfigureAwait(false);
        var entity = result.Result as DynamicTableEntity;
        if (entity == null) return false;//Entity does not exists.
        if (!entity.Properties.ContainsKey("Latitude") || !entity.Properties.ContainsKey("Longitude")) return false;//Either of these attributes do not exist in the entity.
        return true;//All's well. Let's move on to the next record :)
    }