c# - IEnumerable.Any -


i have following method returns jobs date range , status. problem when i'm using ienumerable.any, returns jobs not have specified status. there way fine-tune returns jobs particular status? here's code:

public list<jobdto> getjoblist(int domainid, datetime? datefrom, datetime? dateto, plannedtravelstopstatustypeenum status) {     var context = new webschedulercontext();     var list = new list<jobdto>();      if (datefrom == null)     {         datefrom = datetime.minvalue;     }      if (dateto == null)     {         dateto = datetime.maxvalue;     }      var jobs = context.job.include(j => j.plannedjobstopdetails           .select(jsd => jsd.plannedtravelstop)         )         .where(j => j.minimumstartdate >= datefrom && j.maximumenddate <= dateto &&                **j.plannedjobstopdetails.any**(                  jsd => jsd.plannedtravelstop.plannedtravelstopstatus == status                  ));      foreach (var job in jobs)     {         list.add(new jobdto(job));     }      return list; } 

the code fragment in question :

j.plannedjobstopdetails.any(jsd =>      jsd.plannedtravelstop.plannedtravelstopstatus == status) 

as far can see there 1 : n relation between job , plannedjobstopdetails.

and in statement say: give me job, if any of plannedjobstopdetails (this collection) has "status" for. perhaps want each of plannedjobstopdetails should have same status?

then need change "any" "all":

    var jobs = context.job.include(j => j.plannedjobstopdetails   .select(jsd => jsd.plannedtravelstop) ) .where(j => j.minimumstartdate >= datefrom && j.maximumenddate <= dateto &&        j.plannedjobstopdetails.**all**(          jsd => jsd.plannedtravelstop.plannedtravelstopstatus == status          )); 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -