Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7607301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:37:44+00:00 2026-05-31T00:37:44+00:00

I am trying to pass several search parameters to an LINQ expression to retrieve

  • 0

I am trying to pass several search parameters to an LINQ expression to retrieve all entries that contain one of the search items.

Example:

    Dim query = From p In db.BEW_PROFIL
    For Each searchItem As String In searchItems
        Dim item As String = searchItem
        query = query.Where(Function(p) p.NAME = item)
    Next

Problem here is I don´t get any results because the Where clause looks with that code something like this.

    ... Where p.NAME = item1 AND p.NAME = item2

What i need is an OR between the parameters, but I don´t get it how I can achieve this.

Any help would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:37:45+00:00Added an answer on May 31, 2026 at 12:37 am

    Got it…

    void Main()
    {
        var searchItems = new string[] { "test", "past", "most", "last", "fast", "feast", "yeast", "cast" };
        var query = from p in searchItems select new MyClass { Name = p };
        Predicate<MyClass> whereClause = _ => false;
        foreach (var item in searchItems)
        {
            var searchItem = item;
            Predicate<MyClass> oldClause = whereClause;
            whereClause = p => p.Name == searchItem || oldClause(p);
        }
    
        query = query.Where(p => whereClause(p));
        query.Dump();
    }
    
    public class MyClass
    {
       public MyClass() { }
       public string Name { get; set; }
    }
    

    The code was ran in LINQPad, and that returned every element.

    Here is that code translated to Vb.Net

    Private Sub Main()
        Dim searchItems = New String() {"test", "past", "most", "last", "fast", "feast", "yeast", "cast"}
        Dim query = From p In searchItems Select New [MyClass]() With { .Name = p }
    
        Dim whereClause As Predicate(Of [MyClass]) = Function(element) False
    
        For Each item As String In searchItems
            Dim searchItem = item
            Dim oldClause As Predicate(Of [MyClass]) = whereClause
            whereClause = Function(p) p.Name = searchItem OrElse oldClause(p)
        Next
    
        query = query.Where(Function(p) whereClause(p))
        query.Dump()
    End Sub
    
    Public Class [MyClass]
        Public Sub New()
        End Sub
        Public Property Name() As String
            Get
                Return m_Name
            End Get
            Set
                m_Name = Value
            End Set
        End Property
        Private m_Name As String
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to pass messages between several classes that communicate through interface. However,
im trying to pass two parameters to a function, i being an int value
I am trying to pass a link that contains variables to a mailer model.
I'm trying to pass data that is saved in sessionStorage from background.html to popup.html
I am trying to pass a variable to a a function that I believe
I have a web app with a form that I am trying to pass
trying to develop web form using jquery. all i need is to have several
I'm trying to write a shell script that will make several targets into several
I am trying to use string.format on a url to pass several values into
I am trying to pass a single array object (that is a nsdictionary of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.