var src = (from s in Db.VCT_SITEs
join spl in Db.VCT_SPONSOR_SITE_PRO_LINKINGs on s.SITE_ID equals spl.SITE_ID
join l in Db.VCT_SITE_LOCATIONs on spl.LOCATION_ID equals l.LOCATION_ID
join spd in Db.VCT_SITE_PROTOCOL_DETAILs on spl.PR_SPONSOR_ID equals spd.PR_SPONSOR_ID
join c in Db.VCT_CONTACTs on spd.ADMINISTRATOR_ID equals c.CONTACT_ID
where c.FIRST_NAME.StartsWith(txtFirstName.Text.Trim()) &&
c.LAST_NAME.StartsWith(txtLastName.Text.Trim()) &&
s.SITE_NAME.Contains(txtSiteName.Text.Trim()) &&
spl.PROTOCOL_ID==Convert.ToInt32(ddlProtocol.SelectedValue) &&
l.LOCATION_ID==Convert.ToInt32(ddlLocation.SelectedValue)
select new
{
NAME=c.FIRST_NAME + " " + c.MIDDLE_NAME + " " + c.LAST_NAME,
s.SITE_ID,
l.LOCATION_NAME,
s.PHONE,
s.FAX,
s.SITE_NAME,
s.EMAIL_ID,
s.IS_ACTIVE
}).AsQueryable();
我有這個linq查詢。實際上問題是條件where子句r可選的意思是這些是搜索條件。它們可能包含值或不包含。所以我必須進行檢查,如果(ddlProtocol.selectedIndex!= 0)然後spl.PROTOCOL_ID == Convert.ToInt32(ddlProtocol.SelectedValue)條件工作,否則不工作。如何做到這一點linq中where子句的問題
感謝上面的解決方案。我想再次感謝 – Pankaj 2011-05-11 04:31:30