为什么这个表达式没有给我预期的结果?

时间:2013-11-09 08:00:55

标签: c# linq entity-framework linq-expressions

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 并且小于dtpToDatetxtSearch.Text等于InvoiceNoAlias

1 个答案:

答案 0 :(得分:4)

不是ac.Where(expFromDate);
但是ac=ac.Where(expFromDate);