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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -