c# - 无法对 Azure 存储表查询 lambda 内的字符串属性使用基于字符串的方法

标签 c# azure azure-storage azure-table-storage

在查询 Azure 存储表时出现异常。

这是我的查询:

tableClient.QueryAsync<Resource>(resource => resource.PartitionKey == projectId.ToString()
            && String.Equals(resource.FullName, fullName, StringComparison.InvariantCultureIgnoreCase));

resource.FullNamefullName 都是 string 类型。

但这会引发异常......

Incorrect number of arguments supplied for call to method 'Boolean Equals(System.String, System.String, System.StringComparison)' (Parameter 'method')

同样,如果我添加一个附加条件(在 String.Equals 之前)...

&& !String.IsNullOrWhiteSpace(resource.FullName)

...这会引发异常...

Method IsNullOrWhiteSpace not supported.

如果我将字符串比较更改为...

resource.FullName.ToLower() == fullName.ToLower()

...然后我被告知不支持 ToLower

这是怎么回事?为什么我无法对 string 类型的属性调用 String.EqualsString.IsNullOrWhiteSpace?我是否误解了什么,resource.FullName实际上不是字符串

最佳答案

请遵循以下建议并检查是否有帮助。

  1. 请通过将 String.Equals 更新为 String.Compare 进行检查?
  2. 您可以尝试使用 StringComparison.OrdinalIgnoreCaseString.Compare 方法,而不是使用 ToLower() 方法。实现不区分大小写比较的选项:
tableClient.QueryAsync<Resource>(resource => 
    resource.PartitionKey == projectId.ToString() &&
    String.Compare(resource.FullName, fullName, StringComparison.OrdinalIgnoreCase) == 0);
  • 您还可以将 String.IsNullOrEmpty 方法与 String.Trim 一起使用方法:
  • tableClient.QueryAsync<Resource>(resource => 
        resource.PartitionKey == projectId.ToString() &&
        !String.IsNullOrEmpty(resource.FullName) &&
        !String.IsNullOrEmpty(resource.FullName.Trim()));
    

    希望这有帮助。

    关于c# - 无法对 Azure 存储表查询 lambda 内的字符串属性使用基于字符串的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75943744/

    相关文章:

    .net - Azure WebJobs 有很多 QueueTrigger 不好的做法吗?

    azure - 我的 Azure 订阅 + IAM 访问控制凭证中的所有资源列表

    azure - 将文件从 Azure Blob 存储下载到 Azure Linux VM

    c# - Json.NET 和混淆,反序列化不起作用

    c# - RichtextBox 中的颜色特定单词

    c# - HttpContext.Current.Handler 在静态文件的 PostMapRequestHandler 期间为 null

    c# - 嵌套循环的代码效率 c#

    Azure架构设计

    asp.net - Web 角色内部服务器错误 (500.22)

    c# - 使用 SasLocator 上传到 Azure 媒体服务/blob 存储不显示上传的文件