多條件關聯:
var data = (from h in context.FT_LY
join d in context.FT_LY_Detail
on new { h.Company, h.LYNo } equals new { d.Company, d.LYNo }
where (h.LYDate>=_DateStart) && (h.LYDate<=_DateEnd) && (h.Company==MyCompany)
&& (string.IsNullOrEmpty(_LYNo) || h.LYNo == _LYNo)
&& (string.IsNullOrEmpty(_Item) || d.Item == _Item)
&& (string.IsNullOrEmpty(_ItemName) || d.ItemName == _ItemName)
&& (string.IsNullOrEmpty(_ItemSpec) || d.ItemSpec == _ItemSpec)
select new
{
h.Company,
h.LYNo,
h.LYDate,
h.LYUser,
h.DeptName,
h.Creater,
h.Remark,
h.Audit,
h.Auditor,
h.AuditDate
});
this.gdMain.DataSource = data.ToList().Distinct();