Azure DocumentDB,使用LINQ在字典中搜索

时间:2016-05-09 07:56:29

标签: c# linq azure azure-cosmosdb nosql

您好我在使用

时遇到错误
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查询呢?

谢谢。

1 个答案:

答案 0 :(得分:2)

如果您定义这样的功能:

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

您可以将其更改为: query = query.Where(r =&gt; r.Features [“TKey”]。包含(“T”));

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