实体框架多个基于如果没有被添加

时间:2017-10-06 17:56:55

标签: entity-framework

  Using _webDataDBContext As New WebDataEntities()
            Dim results = _webDataDBContext.coverageareas.Select(Function(x) x)

            If String.IsNullOrEmpty(city) = False Then
                results.Where(Function(x) x.City = city)
            End If

            If String.IsNullOrEmpty(county) = False Then results.Where(Function(x) x.County = county)

            If String.IsNullOrEmpty(state) = False Then results.Where(Function(x) x.State = state)

            If String.IsNullOrEmpty(zip) = False Then results.Where(Function(x) x.Zip = zip)

            Return Await results.ToArrayAsync()
        End Using

不确定为什么这不起作用,当我的if语句满足时,我想在我的结果中附加一个where语句。

然而,即使满足这些陈述,也不会添加这些内容。谁知道为什么?

1 个答案:

答案 0 :(得分:1)

您必须将Where语句分配给IQueryable。

results = results.Where(...)