我有一些现有代码需要修改以搜索多个关键字。(顺便说一句,我对这一切都很陌生)
Dim topics As IQueryable(Of Global.Platform.Core.Data.Topic) = _
From t In _db.Topics
Where t.IsActive = True And t.TopicTitle.Contains(criteria) And t.ForumID = 0 And Not t.TopicTitle.Contains("default") And t.Member.IsActive = True And t.IsActive = True
Order By t.DateCreated Descending
Select t
Take (take_x)
Return topics
我将如何改变这一点,所以如果我输入标准“猫毛”,它将进行 OR 搜索。所以...t.TopicTitle.Contains("cat") OR t.TopicTitle.Contains("hair") ...
。当然,它需要是动态的。
我试过这个,但无法让它工作。
Dim criteriaArr As Array = criteria.Split(" ")
Dim new_criteria As String = " t.TopicTitle.Contains(" + criteriaArr(0) + ")"
If criteriaArr.Length > 1 Then
For Each item As String In criteriaArr
new_criteria += " Or t.TopicTitle.Contains(" + item + ")"
Next
End If
想法是拆分空格并继续附加到 where 子句。我知道在 SQL 中这可能有效,但在这种情况下我将如何进行呢?