如何让 Linq 忽略任何为空的参数?那么姓氏,名字等?如果我在所有参数中都有数据,它工作正常......
refinedresult = From x In theresult _
Where x.<thelastname>.Value.TestPhoneElement(LastName) And _
x.<thefirstname>.Value.TestPhoneElement(FirstName) And _
x.<id>.Value.TestPhoneElement(Id) And _
x.<number>.Value.TestPhoneElement(Telephone) And _
x.<location>.Value.TestPhoneElement(Location) And _
x.<building>.Value.TestPhoneElement(building) And _
x.<department>.Value.TestPhoneElement(Department) _
Select x
Public Function TestPhoneElement(ByVal parent As String, ByVal value2compare As String) As Boolean
'find out if a value is null, if not then compare the passed value to see if it starts with
Dim ret As Boolean = False
If String.IsNullOrEmpty(parent) Then
Return False
End If
If String.IsNullOrEmpty(value2compare) Then
Return ret
Else
ret = parent.ToLower.StartsWith(value2compare.ToLower.Trim)
End If
Return ret
End Function