你能否请我帮助我使用contains(如运算符)提交结果,如下所示......
Public Function GetFromCacheByParentID(ParentID As String, Criteria As String) As List(Of tbl_equip_master)
Dim RelatedData = _RelatedData.GetFromCache
Dim EquipMaster = Me.GetFromCache
return (From e In EquipMaster, r In RelatedData Where r.linked_for = "EQP" And e.global_id = r.child_id And r.parent_id = ParentID And (e.tag_no.Contains(Criteria) Or e.object_name.Contains(Criteria) Or e.object_type.Contains(Criteria)) Select e)
End Function
我的意图是从兑现数据中调用2个结果,并尝试使用contains
加入和过滤但我在" .contains"。
上收到错误答案 0 :(得分:0)
我找出了问题,原因是“e.object_name值为Nothing” - 来自sql server的数据。所以代码“e.object_name.Contains(Criteria)”会抛出错误......
另一个问题是提出如何避免这种情况......任何想法请...
答案 1 :(得分:0)
通过捕获" null"使用以下代码解决了所有问题值
Public Function GetFromCacheByParentID(ParentID As String, Criteria As String) As List(Of tbl_equip_master)
Dim _RelatedData As IRelatedDataV2 = New RelatedDataV2
Dim RelatedData = _RelatedData.GetFromCache
Dim EquipMaster = Me.GetFromCache
Return (From e In EquipMaster, r In RelatedData Where r.linked_for = "EQP" And e.global_id = r.child_id And r.parent_id = ParentID And (e.tag_no.Contains(Criteria) _
Or (Not IsNothing(e.object_name) AndAlso e.object_name.Contains(Criteria))) Select e).ToList
End Function