Conditional Where clause in LINQ

后端 未结 2 627
轮回少年
轮回少年 2021-01-17 02:34

suppose i am showing data in grid and i have many textboxes for filter the data. textbox for employee id. if employee id textbox is empty then no where clause will be added

2条回答
  •  不思量自难忘°
    2021-01-17 03:11

    Try this:-

    First select the data:-

    var r = from t in TblFamilie
    select new
    {
        t.ID,
        t.ParentID,
        t.Name,
        t.CurDate
    };
    

    Then you can filter based on condition:-

       if (sName!="")
            r = r.Where(x => x.Name == sName);
    

提交回复
热议问题