Benny Sutton is 4 hire - just click here

PredicateBuilder usuage with Northwind's Categories table

Here's a query you can run directly in LINQPad demonstrating PredicateBuilder usuage with Northwind's Categories table

LINQPad includes PredicateBuilder - to use, simply press F4 and tick 'Include PredicateBuilder'.

PredicateBuilder is a simple class for dynamically building query filter expressions

This sample returns either the results for an OR for multiple words

Select language > C# Statements on the LINQpad menu, connect your database and specify the table/fields in the code below

             

        string[] keywords = { "meat", "Foo", "sea" };
        var predicate = PredicateBuilder.False<Categories>();

        foreach (string keyword in keywords)
        {
	        string temp = keyword;
                predicate = predicate.Or(p => p.CategoryName.Contains(temp));
        }

    Categories.Where(predicate).Dump();
            // Go to http://www.albahari.com/expressions/ for more info on PredicateBuilder.