I have a situation where I might want to search by order number or by name. I know I can add a Where
expression to my LINQ query, but I only want to add it for the property that I'm searching for! I won't know until the method is called which parameter will be provided, so how can I add the proper condition?
public JsonResult Search(int orderNo=0, string firstName="", string lastName="")
{
if (orderNo >0){
//add Condition
}
if (firstName.Length > 0){
//add Condition
}
if (lastName.Length > 0){
//add Condition
}
//get Result
var result = Repository.Orders.Where(???).OrderByDescending(e=> e.orderNo);
//return
}