Linq If条件中的Where语句VB.net

时间:2018-11-22 01:45:12

标签: .net wpf vb.net linq-to-sql

我被困在LINQ中,我必须根据复选框的值指定where子句。我尝试搜索答案,但是大多数答案都在C#中,而且我不太善于理解其语法。

      Dim recs = From exp In db.exprevs
               Where exp.school_id = currentschool.school_id And exp.type = 1


    If chbid.IsChecked = True Then
        ''here I want to tell the query to filter where ID is something
    End If

    If chbname.IsChecked = True Then
        ''here I want to filter where name is something
    End If

    dgsearchresult.ItemsSource = recs

如果有人指导我如何进一步过滤查询,那就太好了。

1 个答案:

答案 0 :(得分:0)

根据jmcilhinney对帖子的评论,我能够解决自己的问题。为了过滤if语句中的内容,我不得不编写这段简短的代码。

    recs = recs.Where(Function(exp) exp.ID = txtID.text)
相关问题