【问题标题】:Linq for nested object in cosmos db json用于 cosmos db json 中嵌套对象的 Linq
【发布时间】:2021-12-27 20:11:08
【问题描述】:

您好,我无法在 linq 中弄清楚这个 cosmos 查询的等效性

宇宙查询:

select c_option
from c
join c_size in c.size
join c_variant in c_size.variant
join c_option in c_variant.option
where c.type = 'product'
and c_option.optionID = '869' 

还有我的 linq,但它总是返回 null 嗯。

query.SelectMany(product => product.Size
.SelectMany(size => size.Variant
.SelectMany(variant => variant.Option
.Where(option => option.OptionId
.Equals(optionId, StringComparison.OrdinalIgnoreCase))))));

Option 是 product 中的嵌套子对象。嵌套看起来像 product->size->variant->option

Product Model 是一个具有 int/string 类型属性和大小集合的类

public class Product {
 int id {get;set;}
 IList<Size> Size {get;set;}
}
public class Size {
 int id {get;set;}
 IList<Variant> Variant {get;set;}
}
public class Variant {
 int id {get;set;}
 IList<Option> Options {get;set;}
}
public class Option {
 int id {get;set;}
 IList<OptionAvailability> OptionsAvas {get;set;}
}

结果:我需要通过选项 Id 获得一个选项

【问题讨论】:

  • 请展示您的模型,很难理解这里的内容。另外,query 是什么?
  • 你能举例说明你期望什么结果吗?不清楚

标签: c# linq azure-cosmosdb


【解决方案1】:

原来我在 json 属性中遇到拼写问题,optionID 而不是 optionId。除此之外,现在一切正常。

干杯。

【讨论】:

  • 您能否接受作为答案(单击答案旁边的复选标记,将其从灰色切换为已填充。)。这对其他社区成员可能是有益的。谢谢
猜你喜欢
  • 2021-12-14
  • 2019-01-25
  • 2019-01-21
  • 1970-01-01
  • 2019-04-21
  • 1970-01-01
  • 1970-01-01
  • 2020-04-25
  • 2022-12-17
相关资源
最近更新 更多