我有如下代码,如果FirstName
(来自视图)具有数据,则在此代码中,它会向criteria
列表添加条件:
var criteria = new List<Predicate<ContactItem>>();
if (!IsNullOrEmpty(modelPage.FirstName))
{
criteria.Add(o => o.FirstName.Contains(modelPage.FirstName));
}
list = _contactRepository.Query().Where(c => criteria.All(pred => pred(c)));
可以,但是在下面的代码中,当Count()
运行时,我收到了modelPage.FirstName
的空异常错误...!
var totalRecords = list.Count();