Benny Sutton is 4 hire - just click here
Conditional queries using LINQpad
Here's a query you can run directly in LINQPad to create a conditional query
Select language > C# Program on the LINQpad menu, connect your database and specify the table/fields in the code below
void ConditionalQuery(int? CatId, String SearchTerm)
{
IEnumerable<Photo> query;
query = this.Photos;
if (CatId.HasValue)
query = query.Where(r => r.CategoryID == CatId);
if (!String.IsNullOrEmpty(SearchTerm))
query = query.Where(r => r.Description.Contains(SearchTerm));
query = query.OrderByDescending(r => r.Id);
query.Dump();
}
void Main()
{
ConditionalQuery(767, "snow");
}
Go to http://www.albahari.com/expressions/ for more info on PredicateBuilder
Using PredicateBuilder to do an OR search