【发布时间】:2025-11-23 19:15:01
【问题描述】:
我有以下关系(例如)
A 包含一个或多个 B
每个 B 包含一个或多个 C 和 D
我想使用 SelectMany 以及一些搜索条件来展平所有内容并获得 A,B,C 和 D's 。这就是我所拥有的。
context.A.Where(a => (string.IsNullOrEmpty(name) || a.Name.Contains(name)))
.SelectMany(ab =>ab.b.Where(n=>n.bname.Contains(name) || string.IsNullOrEmpty(name)),
(aa, bb) => new { aa, bb }) //gets all a's and b's
.SelectMany(bc => bb.c.Where(w => w.KEYWORD.Contains(Keyword) || string.IsNullOrEmpty(Keyword)),
(bc,words) => new {bc,kwords}) //gets all b's and c's
我做的对吗?如果是这样,那么如何将 B 与所有 D 添加到上述表达式中?
【问题讨论】:
-
我建议你在这种情况下使用查询语法。