我正在编辑我以前的代码
return phases
.OfType<ServicePhase>()
.Where(p => p.Service.Code == par.Service.Code)
.Cast<ParPhase>()
但是现在我希望它包括两者
return phases
.OfType<ServicePhase>()
.Where(p => p.Service.Code == par.Service.Code)
.Cast<ParPhase>()
.OfType<ParTypePhase>()
.Where(p => p.ParType.Code == par.Type.Code)
.Cast<ParPhase>();
如何将这两个合并在一起
最佳答案
使用Concat
或Union
方法。
示例:
var result =
phases
.OfType<ServicePhase>()
.Where(p => p.Service.Code == par.Service.Code)
.Cast<ParPhase>()
.Union(
phases.OfType<ParTypePhase>()
.Where(p => p.ParType.Code == par.Type.Code)
.Cast<ParPhase>()
);
关于c# - 需要帮助合并两个 LINQ 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8013682/