如果参数为null或空FE,我需要忽略WHERE语句中的部分或全部条件:
我有简单的LINQ查询
var query = from x in context.a
where x.p == param1 && x.i == param2
select x;
Run Code Online (Sandbox Code Playgroud)
x.p == param1如果param1为null或emty,我该如何忽略?
试过这个
var query = from myLog in myContext.ApsValidationLogs
where (myLog.systemtype == comboBoxSystemType.SelectedItem.ToString() || string.IsNullOrEmpty(comboBoxSystemType.SelectedItem.ToString()))
&& (myLog.bankid == comboBoxBankId.SelectedItem.ToString() || string.IsNullOrEmpty(comboBoxBankId.SelectedItem.ToString())))
select myLog;
Run Code Online (Sandbox Code Playgroud)
但得到了
Object reference not set to an instance of an object.
Run Code Online (Sandbox Code Playgroud)
如果第二个组合框的项目为空.怎么了?