Combine foreach with linq

How to change the following code to a single LINQ query:

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);
}
+3
source share
2 answers

Use .ForEach in LINQ:

(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)
         );
+2
source

Try this attempt (excluding all this nonsense);

Collection.Where(s => s.RadocID == docID && ...).ToList().ForEach(s => EmailHelper.notify(s));
+1
source

All Articles