【问题标题】:Azure DocumentDB , Search In Dictionary with LINQAzure DocumentDB,使用 LINQ 在字典中搜索
【发布时间】:2016-05-09 07:56:28
【问题描述】:

您好,我在使用时遇到错误

query = query.Where(r => r.Features.ContainsValue(fuelType)); 

这是我的模型

public class VehicleResponse 
        {
            [JsonProperty(PropertyName = "id")]
            public string Id { get; set; }

            public Vehicle Vehicle { get; set; }

            public List<string> PhotoUrls { get; set; }

            public string VideoUrl { get; set; }

            public Dictionary<string, string> Features { get; set; }

            public List<string> Equipments { get; set; }

            public VehicleResponse()
            {
                this.PhotoUrls = new List<string>();
            }
        }

DocumentDB 不支持“ContainsValue”方法。那么我应该如何更改我的 LINQ 查询呢?

谢谢。

【问题讨论】:

    标签: c# linq azure azure-cosmosdb nosql


    【解决方案1】:

    如果你这样定义你的特性:

      "Features": {
        "TKey": "TK1",
        "TValue": "TV1"
      }
    

    您可以将其更改为: query = query.Where(r => r.Features["TKey"].Contains("T"));

    您可以阅读documents 以获取更多信息。

    【讨论】:

    • 谢谢它成功了!顺便说一句,您对如何为 List 做同样的事情有任何想法吗?
    • 类似数组,可以直接使用Contains,如Where(f =&gt; f.Equipments.Contains("E"))
    • 它不是来自包含在 List 中的干净结果,我只是将列表项附加到原始字符串,效果更好。
    • 向我展示您的 VehicleResponse 的 JSON 文档
    猜你喜欢
    • 1970-01-01
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 2018-01-08
    • 2015-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多