c# - Dynamic Linq in Asp.net Core?
问题描述
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.
解决方案
推荐阅读
- html - 其他文件夹中文件的相对路径
- rust - 如何将结构体的 vec 作为元组进行迭代?
- sonarqube - 由于超时异常,无法执行 SonarScanner 分析
- c++ - Boost二进制禁止(通过猎人下载)
- sql - 以分钟为单位的 Teradata 时间戳减法
- python - 在工作线程/循环中运行异步函数
- python - 将输入传递给 json 以打开正确的 json 文件
- python - PyAutoGui 图像识别问题
- vb.net - Visual basic:我的日历搜索只搜索一年中的第一个月而不是实际月份
- python - 如何让 p5(用 Python 处理)在 Google Colab 中显示?