where 절에 여러 값이있는 LINQ 쿼리가 있습니다. where 절의 값은 filterbox from checkboxlist의 값입니다. Checkboxlist는 Null (또는 예를 들어 빈 문자열)을 반환 할 수 있습니다. 즉, checkboxlist에서 none을 선택하면 모두 선택한다는 의미로 쿼리에서 where 절이 필요하지 않습니다. 나는 그것을 처리 할 수있는 하나의 좋은 LINQ를 작성하는 방법을 몰랐다. 그래서 나는 아래와 같이 여러 개의 쿼리와 함께 여러 개의 IF 문을 사용했다. 나는 그것을 테스트했고 where 절에서 2 개의 매개 변수로 지금까지는 잘 작동한다. 그러나 실제로는 쿼리에 전달할 매개 변수가 더 많이 필요하며 해당 작업을 수행하기 위해 많은 IF 문이 있어야 지저분 해집니다. 하나의 좋은 LINQ 쿼리에서 어떻게 처리 할 수 있습니까?여러 where 절을 사용하여 LINQ의 Null 값을 처리하는 방법
Function FilterCol(ByVal col As List(Of ProductDetails), Optional SelectedCategory As List(Of String) = Nothing, Optional SelectedBrand As List(Of String) = Nothing) As List(Of ProductDetails)
Dim strSelectedCategory As String = String.Join(",", SelectedCategory .ToArray())
Dim strSelectedBrand As String = String.Join(",", SelectedBrand .ToArray())
If strSelectedCategory = "" And strSelectedBrand = "" Then
Return col
ElseIf strSelectedCategory = "" Then
Dim res1 As IEnumerable(Of StatsDetails) = From x In col Where strSelectedBrand.Contains(x.Brand) Select x
Return res1.ToList
ElseIf strSelectedBrand = "" Then
Dim res2 As IEnumerable(Of StatsDetails) = From x In col Where strSelectedCategory.Contains(x.Category) Select x
Return res2.ToList
Else
Dim res As IEnumerable(Of StatsDetails) = From x In col Where strSelectedCategory.Contains(x.Category) And strSelectedBrand.Contains(x.Brand) Select x
Return res.ToList
End If
End Function
NULL을 지정하면 DbNull 또는 VB의 Nothing이 발생합니까? –