Search for multiple keywords using LINQ vb

DaveG

New Member
I have some existing code that I need to modify to search more than one keyword. (I am new to all this by the way)\[code\]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\[/code\]How would i go about changing this so if I entered criteria "cat hair" it would do an OR search. so \[code\]...t.TopicTitle.Contains("cat") OR t.TopicTitle.Contains("hair") ...\[/code\].Of course it would need to be dynamic.I tried this but could not get it to work.\[code\]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\[/code\]The idea was to split the spaces and keep appending to the where clause. I know in SQL this might have worked, but how would I go about in this scenario?
 
Back
Top