Link to home
Start Free TrialLog in
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?
ASKER CERTIFIED SOLUTION
Avatar of PagodNaUtak
PagodNaUtak
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mark32123
mark32123

ASKER

That was exactly what I needed.  Thanks.