I have a database table that contains product models. All model names adhere to a strict nomenclature. The code position I am dealing with is the very last character of the model name and I need to retrieve only those model names using the following criteria:
Last char == "E"
Last char <> "E"
All model names
There are 2 checkboxes on the UI. At least one checkbox must be ticked. The user can also tick both. If both checkboxes are ticked then all product models need to be returned. If one checkbox is ticked only those product models ending with "E" should be returned. If the other checkbox is ticked product models not ending with "E" should be returned. Kind of like, true or false, or both.
Only product models ending with "E" model.checkbox1 && !model.checkbox2;
Only product models not ending with "E" !model.checkbox1 && model.checkbox2;
All product models model.checkbox1 && model.checkbox2;
Is there a way of combining the above logic into a single Lambda expression? My existing Lambda to retrieve all product models is:
IList<SelectListItem> items = db.Products
.Select(m => new SelectListItem() { Text = m.Name, Value = m.Id.ToString() })
.ToList();
I know I can use .Where(m => m.Name.EndsWith("E"))
but that only takes care of the first condition above.