How query specific item from json object which has dictionary?

Author: 191180rk

Originally Sourced from: https://stackoverflow.com/questions/72267704/how-query-specific-item-from-json-object-which-has-dictionary

How to query the below json object collection using SQL/LINQ, to get 'ordername' which has item(s) ONLY from particular 'factory' i.e., factory1?

Note: json object collections are nothing but cosmos db collection

I know below json structure can be improved, by replacing dictionary with array but that change not feasible at the moment.

  {
  id:123,
  ordername:order1,
  itemdictionary: {
    item1: {
      id: "item1",
      name: "milk",
      manufacture:
       {
       name:factory1,
       location:location1
       }
    },
    item2: {
      id: "item2",
      name: "curd",
      manufacture:
       {
       name:factory2,
       location:location2
       }
    }
   }
   orderamt:"5$"
  }

{
  id:1234,
  ordername:order2,
  itemdictionary: {
    item1: {
      id: "item1";
      name: "honey",
      manufacture:
       {
       name:factory3,
       location:location3
       }
    },
    item2: {
      id: "item2",
      name: "milk",
      manufacture:
       {
       name:factory1,
       location:location1
       }
    }
  }
  orderamt:"7$"
}

c# representation:

public class OrderModel
{  
    public string OrderAmt{ get; set; }
    public string Id{ get; set; }
    public Dictionary<string,ItemDescription> ItemDictionary{ get; set; }
    public class ItemDescription
    {
      public string Id { get; set; }
      public string Name{ get; set; }
      public Manufacture Manufacture{ get; set; }
    }
} 

public class Manufacture 
{
    public string Location{ get; set; }
    public string Name{ get; set; }
 }

Query tried, returning all records without applying filter but need to apply filter like (manufacture.name == "factory1") :

 var query = dbClient.CreateDocumentQuery<OrderModel>(collectionUri, 
 feedOptions).Where(w => w.ItemDictionary.Values.Where(i => 
 i.manufacture.name == "factory1") != null).AsDocumentQuery();