with the below, the model.Status and model.Source values may or may not be null. If null, I want the expression to pull all statuses/sources. Is this possible with lambda because the below statement is not working?
var leads = db.CallCenterLead.Include("Profile").Include("Account")
.Where(x => x.DateSent >= model.DateFrom && x.DateSent <= model.DateTo
&& ((model.Status != null && x.Status == model.Status) || (model.Status == null))
&& (model.Source != null && x.Source == model.Source)).OrderByDescending(x => x.DateSent).ToList();
One way to do this is to use an extension method, like this:
The extension method:
The method adds the predicate if the condition is true. Otherwise it just returns the source as it were.