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
Post a Comment