简体   繁体   中英

Linq for nested object in cosmos db json

Hi there I cant figure out euivalent of this cosmos query in linq

Cosmos Query:

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' 

And my linq but it returns null all the time ehh.

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

Option is nested child object in product . Nesting looks like that product->size->variant->option

Product Model is a class with properties of type int/string and also collection of size

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;}
}

Result: I need to get an option by option Id

It tured out I got a spelling issue in the json property, optionID instead of optionId. Besides that everything works now.

Cheers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM