2012年8月8日 星期三

LINQ 動態組條件式


範例:如果a0,就不要作條件式sch.filed1 == b
var systemA = from sch in db.dbname
                          let isAppendWhere = (a == "0")
                          where sch.sys_lockmark.ToString().Trim() == "00"
                         && (isAppendWhere? true : sch.filed1 == b)
                          select sch;



l   let isAppendWhere= (a == "0")
說明:要給isSearchAll一個布林值

l   (isAppendWhere? true : sch.filed1 == b)
這是if的簡短式,(條件? true作的事” : false作的事”)
所以如果isAppendWheretrue,就作true(等於沒條件)
反之若如果isAppendWherefalse,就作sch.filed1 == b 條件式