So I have managed to get this query working
List<string> listStatus = new List<string>() ; listStatus.add("Text1"); List<string> listMerchants = new List<string>() ; listMerchants.add("Text2"); from item in db.vw_Dropship_OrderItems where listStatus.Contains(item.StatusCode) && listMerchants.Contains(item.MerchantId) select item;
Here I would like to check if listStatus and listMerchants are not null only then put them inside WHERE clause.
Like
if listMerchants is null then query will be like
where listStatus.Contains(item.StatusCode)
I do not want to use switch or If condition.
Thanks
from item in db.vw_Dropship_OrderItems where (listStatus != null ? listStatus.Contains(item.StatusCode) : true) && (listMerchants != null ? listMerchants.Contains(item.MerchantId) : true) select item;
Might give strange behavior if both listMerchants and listStatus are both null.
Well, you're going to have to check for null somewhere. You could do something like this:
from item in db.vw_Dropship_OrderItems where (listStatus == null || listStatus.Contains(item.StatusCode)) && (listMerchants == null || listMerchants.Contains(item.MerchantId)) select item;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With