I'm looking to update one of my queries as the requirements for the search has changed. Originally, the user was to enter a single SKU and a mfg. date range to search the product catalog. So this is what I used.
DateTime startDate = ...;
DateTime endDate = ...;
string prodSKU = TextSKU.Text.Trim();
var results = from c in db.Products
where c.is_disabled == false
&& c.dom >= startDate
&& c.dom <= endDate
&& c.sku.StartsWith(prodSKU)
select c;
Now the requirement says that the user can enter a comma delimted list of SKUs into the textbox to search. What I'm stumped about is how to find all the products in the mfg. date range that begin with any of the SKUs in skuList (w/o using a fornext loop).
string prodSKU = TextSKU.Text.Trim();
List<string> skuList = prodSKU.Split(new char[] { ', ' }).ToList();
var results = from c in db.Products
where c.is_disabled == false
&& c.dom >= startDate
&& c.dom <= endDate
// && c.sku.StartsWith(prodSKU)
select c;
Any ideas would be greatly appreciated!
EDIT: I'll put this here even though this question is already answered.
I achieved the same as the accepted solution, but using an extension method to aid readability:
and then the solution is:
Something like