Reputation: 70
How to change the following code to one 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);
}
Upvotes: 3
Views: 525
Reputation: 48114
Give this a try (excluding all this include nonsense);
Collection.Where(s => s.RadocID == docID && ...).ToList().ForEach(s => EmailHelper.notify(s));
Upvotes: 1
Reputation: 300
Use .ForEach in the 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)
);
Upvotes: 2