I have a stored procedure in my DB that allows me to send nulls as parameters. If the value is null then it's used in the where statement. However, I don't need to query the database a second time because I have the data in a binding list.
I have been trying to figure out a way to accomplish the same task in a Linq statement. Below is the Linq code I have now. Sometimes the jobname or jobnumber could be empty. Is there any way to include an operator to say if not empty, use it in the where clause? So far the only way I got it to work is to have a deep if/else statement. I was looking around and it looks like the only way to do this is with a lambda expression and not a Linq? But I have no idea on how to accomplish that with a binding list?
t = new BindingList<Tracking>(
OmanWorkflow.TrackingData.Where(o => o.Created >= dateFrom.Value
&& o.Created <= dateTo.Value
&& o.JobNumber.Contains(txtFilterJobNumber.Text)
&& o.JobName.Contains(txtFilterJobName.Text)
).ToList());
Whereclause with&&in it, use multipleWhereclauses.var query = OmanWorkflow.TrackingData.Where(o => o.Created >= dateFrom.Value && o.Created <= dateTo.Value); if (!string.IsNullOrEmpty(txtFilterJobNumber.Text)) { query = query.Where(z => o.JobNumber.Contains(txtFilterJobNumber.Text)) }etc.