Guest User

Untitled

a guest
Jun 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. Public Function GetDocuments(criteria as String)
  2. Dim splitCriteria = SplitTheCriteria(criteria)
  3.  
  4. dim query = from document in _context.Documents
  5.  
  6. For Each item in splitCriteria
  7. Dim localItem = item
  8. query = AddCriteriaToQuery(query, localItem)
  9. Next
  10.  
  11. dim matchingDocuments = query.ToList()
  12. End Function
  13.  
  14. Private Function AddCriteriaToQuery(query as IQueryable(Of Document), criteria as string) as IQueryable(Of Document)
  15. return query.Where(Function(doc) doc.Name = criteria)
  16. End Function
  17.  
  18. Public Class Doc
  19.  
  20. Private _docName As String
  21. Public Property DocName() As String
  22. Get
  23. Return _docName
  24. End Get
  25. Set(ByVal value As String)
  26. _docName = value
  27. End Set
  28. End Property
  29.  
  30. Public Sub New(ByVal newDocName As String)
  31. _docName = newDocName
  32. End Sub
  33. End Class
  34.  
  35. Sub Main()
  36. Dim Documents As New List(Of Doc)
  37. Documents.Add(New Doc("ABC"))
  38. Documents.Add(New Doc("DEF"))
  39. Documents.Add(New Doc("GHI"))
  40. Documents.Add(New Doc("ABC DEF"))
  41. Documents.Add(New Doc("DEF GHI"))
  42. Documents.Add(New Doc("GHI LMN"))
  43.  
  44. Dim qry = From docs In Documents
  45.  
  46. qry = qry.Where(Function(d) d.DocName.Contains("GHI"))
  47.  
  48. Dim qryResults As List(Of Doc) = qry.ToList()
  49.  
  50. For Each d As Doc In qryResults
  51. Console.WriteLine(d.DocName)
  52. Next
  53.  
  54. End Sub
  55.  
  56. query = query.where(Function(s) s = "ABC")
Add Comment
Please, Sign In to add comment