0
我有一個傳遞一個或多個提供程序代碼的WebGet。對於每個供應商代碼,我需要爲其所在代碼存在的所有住院患者返回患者列表,作爲接受,出席或諮詢供應商。在WCF數據服務中構建LINQ查詢的Where子句
應該是:
WHERE (inpatient = 1)
AND (dischargeddate IS NULL)
AND ((attending = 'SMITH') OR (admitting = 'SMITH') OR (consulting = 'SMITH'))
的 「for」 循環不附加條件的where子句。我究竟做錯了什麼??
感謝
[WebGet]
public IQueryable<vw_patient> 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)
&& p.dischargedate.Equals(null)
select p);
foreach (string provider in providers)
{
results = results.Where<vw_patient>(e => e.attending.Equals(provider) || e.admitting.Equals(provider) || e.consulting.Contains(provider));
}
results.OrderBy(p => p.roomloc).ThenByDescending(p => p.patientname);
return results;
}
else
{
var results = (from p in this.CurrentDataSource.vw_patient
where p.patientname.StartsWith(searchtext)
&& p.inpatient.Equals(true)
&& p.dischargedate.Equals(null)
select p);
foreach (string provider in providers)
{
results = results.Where<vw_patient>(e => e.attending.Equals(provider) || e.admitting.Equals(provider) || e.consulting.Contains(provider));
}
results.OrderBy(p => p.roomloc).ThenByDescending(p => p.patientname);
return results;
}
}
謝謝鄧肯......這很好! 我假設這是返回結果的方式: return fulllist.AsQueryable(); –
user680891
2011-05-11 12:49:39
@ user680891:沒有probs。返回看起來也不錯。 – 2011-05-11 12:54:46