Avatar of mark32123
mark32123 asked on

Build LINQ query at runtime

I am trying to use LINQ to create custom filters.  My goal is to allow for the where clause of the LINQ query to change depending on what the user selects.

My main goal is to filter by selected names in a multi select listbox.

I am trying to do something along these lines

USER SELECTED ITEMS
For Each itm In ListBox1.SelectedItems
            strg +=  itm.ToString & " Or "
        Next


LINQ
Dim qry = (From invoice In tblCashIn.GetData
                   Where invoice.Customer_Name = strg
                  Select invoice.Customer_Name).ToList

What I am having trouble with is embedding the Or operator (or any operator, AND, XOR, AndAlso, etc...).  Since I am building the Or in as a string, the Where statement in the LINQ query does not pickup that it should be multiple parameters to search for.

Any help would be great.  I am not 100% sure this is possible with LINQ, if it is not, it would be great if you might have some comparable way of accomplishing my goal (Excluding basic SQL queries, I am trying to keep everything strongly typed if possible).

PS:  Is this what DLINQ is supposed to accomplish?
Visual Basic.NET

Avatar of undefined
Last Comment
mark32123

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
PagodNaUtak

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
mark32123

That was exactly what I needed.  Thanks.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23