If else condition in multiple from in LINQ in C# -



If else condition in multiple from in LINQ in C# -

i have linq query need set status if p.conditionvariable > 0 apply next condition.

from prob in table2.where(p => p.id == p.conditionvariable && !p.isblocked && p.isactive)

if p.conditionvariable == 0 next remains same.

(from _obj1 in table1.where(p => p.isactive == true)) prob in table2.where(p => p.id == _obj1.id && !p.isblocked && p.isactive && p.conditionvariable == 0) select new class1 { title = prob.title, status = prob.ispending, id = obj1.id }

i think want create || between conditions , table2 queried based on p.condtionvariable.

(from _obj1 in table1.where(p => p.isactive == true)) prob in table2.where(p => (p.id == _obj1.id && !p.isblocked && p.isactive && p.conditionvariable == 0) || (p.conditionvariable > 0 && p.id == p.conditionvariable && !p.isblocked && p.isactive)) select new class1 { title = prob.title, status = prob.ispending, id = _obj1.id }

if want utilize if/else conditions, can utilize this

(from _obj1 in table1.where(p => p.isactive == true)) prob in table2.where(p => { bool state = false; if(p.conditionvariable > 0) { state = p.id == p.conditionvariable && !p.isblocked && p.isactive; } else if(p.conditionvariable == 0) { state = p.id == _obj1.id && !p.isblocked && p.isactive; } homecoming state; }) select new class1 { title = prob.title, status = prob.ispending, id = _obj1.id }

c# linq

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -