我需要一个.Where()条款/运算符
List<Guid> ExistingChildrenIDsFromParentsIcollectionJoinParentChildM2M =
this.parent
.SelectMany(
p => p.joinParentChildM2M?
.Select(jpc => jpc.ChildID)
?? new List<Guid> {Guid.Empty} //tried similar, but didn't understand the type needs of .SelectMany
)
.ToList();
Run Code Online (Sandbox Code Playgroud)
我在洞里大约有 10 个搜索/40 个结果,但在这件事上一无所获……TIA!
该语句抛出 NullReferenceException :
(p.joinParentChildM2M 有时初始化为 null 有时不初始化)
List<Guid> ExistingChildrenIDsFromParentsIcollectionJoinParentChildM2M =
this.parent
.SelectMany(
p => p.joinParentChildM2M? //shouldn't this Null Conditional Operator break the chain?
.Select(jpc => jpc.ChildID)
)
.ToList()
??
GuidEmptyList();
Run Code Online (Sandbox Code Playgroud)
我试过:
- 移动 Coalesce ?? 在 SelectMany Parens() 中
- 添加 DefaultIfEmpty(意识到空与 …