Can I and how would I pass an array of strings to a Linq query, so that the elements of the array feed the Where clause, like in example below?
If one of arrays is empty, the query should still work (just ignore the respective where clause).
Would the query change if instead of array one passess e.g. a list like List<string> brands
, List<string> categories
etc.?
private IEnumerable<LatestReading> getLatestReadings(string[] brands, string[] categories)
{
return
from reading in context.Readings
join product in context.Products
on reading.ProductId equals product.SkuCode
// where product.Brand is one or more brands from string[] brands
// where product.Category is one or more categories from string[] categories
where reading.Date == lastReadingDate
select new LatestReading
{
ProductId = reading.ProductId,
Distributor = reading.Distributor,
Price = reading.Price
};
}