c# - How to add conditional condition to LINQ query based on a previously returned value -
for example:
var slist = asl in aslist asl.description == as.tostring() select asl; = slist.firstordefault(); var rlist = arl in arlist arl.description == rdescription && arl.id == as.id select arl;
now see, last condition of rlist
query (i.e. && arl.id == as.id
) based on value retrieved slist
query. problem when slist
null
, error. want include last condition (i.e. && arl.id == as.id
) if slist
not null.
i can using if else shown below, want elegantly using linq if possible:
if (as != null) { // include arl.id == as.id condition in query } else { // exclude arl.id == as.id condition query }
thanks in advance!
&& (assetsensor == null || arl.sensorid == assetsensor.id)
Comments
Post a Comment