Expression<Func<BAL.Receipt, bool>> expKeyword = x => x.InvoiceNo.StartsWith(txtSearch.Text) | x.Alias.StartsWith(txtSearch.Text);
Expression<Func<BAL.Receipt, bool>> expFromDate = x => x.Date > dtpFrom.DateTime.Date;
Expression<Func<BAL.Receipt, bool>> expToDate = x => x.Date <= dtpTo.DateTime;
var ac = BAL.ApplicationInfo.db.Receipts.Where(expKeyword);
if (dtpFrom.EditValue != null)
ac.Where(expFromDate);
if ( dtpTo.EditValue != null )
ac.Where(expToDate);
预期结果应返回日期大于Receipts
日期的所有dtpFrom
并且小于dtpToDate
和txtSearch.Text
等于InvoiceNo
或Alias
答案 0 :(得分:4)
不是ac.Where(expFromDate);
但是ac=ac.Where(expFromDate);