c# - 如何通过 IEnumerable 使用 TableQuery 进行查询?

标签 c# .net azure azure-table-storage azure-tablequery

我通过以下方法公开我的表:

public static class TableCacheService
{
    public static IEnumerable<Myentity> Read()
    {
        var acc = new CloudStorageAccount(
                     new StorageCredentials("account", "mypass"), false);
        var tableClient = acc.CreateCloudTableClient();
        var table = tableClient.GetTableReference("Myentity");
        return table.ExecuteQuery(new TableQuery<Myentity>());
    }
}

这是一个使用示例:

    var nodeHasValue = TableCacheService.Read()
                                        .Where(x => note.ToLower().Contains(x.RowKey.ToLower()))
                                        .Any();

但据说x.RowKey为空!

enter image description here

看起来有 2 个成员都称为 RowKey。其中之一是 TableEntity:

enter image description here

如何访问非空的 RowKey?我是否错误地查询了表?

最佳答案

您似乎在 Myentity 类中隐藏了 RowKeyPartitionKey 属性。

我猜你的Myentity类有类似的东西:

public class Myentity: TableEntity
{
    public new string RowKey { get; set; }
    ...
}

注意关键字new

如果您有此构造,则需要删除此属性。

有关隐藏和覆盖的更多信息,您可以找到 here .

另请查看 ATS(Azure 表存储)的工作示例 here .

关于c# - 如何通过 IEnumerable 使用 TableQuery 进行查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52193134/

相关文章:

azure - Azure 应用服务上带有 OWIN 'SystemWeb' 的 Web API 应用程序

Azure WebJob-Project - 访问父项目项目

javascript - 限制 Azure API 在我的域中的使用

如果数据库列中的值达到零值,则 C# 进行条件处理

c# - 使用析构函数分离事件

c# - 如何使用字典引用动态类型?

c# - BackgroundWorker 中仅更新了 2 个进度条中的 1 个

c# - LInq left join with multiple condition in on 子句

c# - Linq-To-SQL Marc Gravell 的 InRange 扩展

c# - LINQ to SQL 类