如何让LINQ到忽略是空的任何参数?所以姓,名,等等?如果我在所有参数正常工作数据...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
我会尝试感谢你回答。 +1这样一个很好的详细的尝试,我会报告,如果它的工作。再次感谢。 – 2010-04-20 20:07:22
好的,我在代码中犯了一个错误。我真的想要“和”每个参数。当我在试图让它工作的时候,我从那里得到了操作系统。所以最终我目前没有得到任何结果。 (我更新了问题)我得到结果的唯一时间是如果所有参数都有。所以是的,它与任何参数中的空字符串有关。 – 2010-04-20 20:20:09
那么,你想* TestPhoneElement *返回真或假在其中* value2compare *参数为空字符串(或没有)的情况下? – 2010-04-21 13:04:02