c# - Linq to Entity - How to concatenate conditions -


i writing linq query. there way can concatenate query based on if conditions?

like on query is

    res in _db.person     res.departments.id == deptid     select res; 

and if have condition true, like

from res in _db.person     res.departments.id == deptid && res.departments.type == depttype     select res; 

assuming condition in variable condition

from res in _db.person res.departments.id == deptid && (!condition || res.departments.type == depttype) select res; 

version or requested

from res in _db.person res.departments.id == deptid || (condition && res.departments.type == depttype)) select res; 

alternatively may wish use predicate builder


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -