gpt4 book ai didi

c# - 结合 foreach 和 linq

转载 作者:行者123 更新时间:2023-11-30 16:13:11 24 4
gpt4 key购买 nike

如何将以下代码更改为一个 LINQ 查询:

var items = (from s in db.WfRADocStates.Include(x => x.WfStateStatu)
.Include(xx => xx.WfState)
.Include(xxx => xxx.WfState.Dept)
.Include(d => d.RADoc)
where s.RADocID == docID
&& !s.isHistory
&& s.StatusID == 1
&& s.WfStateStatu.isToNotify
select s).ToList();

foreach (var item in items)
{
EmailHelper.notify(item);
}

最佳答案

在 LINQ 中使用 .ForEach :

(from s in db.WfRADocStates.Include(x=>x.WfStateStatu).Include(xx=>xx.WfState).Include(xxx=>xxx.WfState.Dept).Include(d=>d.RADoc)
where
s.RADocID == docID &&
!s.isHistory &&
s.StatusID == 1 &&
s.WfStateStatu.isToNotifyCNH
select s).ToList().ForEach(
s => EmailHelper.notify(s)
);

关于c# - 结合 foreach 和 linq,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22031956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com