Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding where clause for LINQ query in WCF data service
    text
    copied!<p>I have a WebGet that is passed one or more provider codes. For each provider code, I need to return a patient list for all inpatients where their code exists as admitting,attending or consulting provider.</p> <p>Should be:</p> <pre><code>WHERE (inpatient = 1) AND (dischargeddate IS NULL) AND ((attending = 'SMITH') OR (admitting = 'SMITH') OR (consulting = 'SMITH')) </code></pre> <p>The "for" loop is not appending the criteria to the where clause. What am I doing wrong?? </p> <p>Thanks</p> <pre><code> [WebGet] public IQueryable&lt;vw_patient&gt; GetInpatients(string providercode, string searchtext) { string[] providers = providercode.Split(new char[] { '|' }); if (string.IsNullOrEmpty(searchtext)) { var results = (from p in this.CurrentDataSource.vw_patient where p.inpatient.Equals(true) &amp;&amp; p.dischargedate.Equals(null) select p); foreach (string provider in providers) { results = results.Where&lt;vw_patient&gt;(e =&gt; e.attending.Equals(provider) || e.admitting.Equals(provider) || e.consulting.Contains(provider)); } results.OrderBy(p =&gt; p.roomloc).ThenByDescending(p =&gt; p.patientname); return results; } else { var results = (from p in this.CurrentDataSource.vw_patient where p.patientname.StartsWith(searchtext) &amp;&amp; p.inpatient.Equals(true) &amp;&amp; p.dischargedate.Equals(null) select p); foreach (string provider in providers) { results = results.Where&lt;vw_patient&gt;(e =&gt; e.attending.Equals(provider) || e.admitting.Equals(provider) || e.consulting.Contains(provider)); } results.OrderBy(p =&gt; p.roomloc).ThenByDescending(p =&gt; p.patientname); return results; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload