0

I have a collection of Json data that I convert into a List<Dictionary<string, object>> I have to then filter that list and select some column out but the conditions of what to use for the filter/select will be different depending on different scenarios.

How can I dynamically build a linq statement?

items.Where(x => x.ContainsKey("A") && x.ContainsKey("B") && x.ContainsKey("C"))
        .Select(x => new { a = (string)x["A"], b = (string)x["B"], c = Convert.ToInt32(x["C"]) }).ToList();

Sometimes it maybe an "or" statement instead of "and". I do anticipate the where clause conditions will match the select conditions.

chobo2
  • 83,322
  • 195
  • 530
  • 832
  • This feels like an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). What is it you actually trying to achieve – Nkosi Oct 28 '18 at 23:34
  • Assuming the following is also related https://stackoverflow.com/questions/53036912/build-where-clause-dynamically-in-ado-net-c-sharp – Nkosi Oct 28 '18 at 23:40

0 Answers0