I’m attempting a LINQ to SQL query where the year filter can either represent multiple specific years, like “2009,2008,2007”, or a wildcard symbol, “%”, to match any year. Currently, the query works when given a list of specific years but fails when using the wildcard. How can I modify the query to correctly handle both cases?
if (yearParam == "%") {
var records = (from rec in db.harvestEntries
orderby rec.entryId
select new { rec.entryId, rec.year, rec.category }).ToList();
} else {
var allowedYears = yearParam.Split(",");
var records = (from rec in db.harvestEntries
where allowedYears.Contains(rec.year.ToString())
orderby rec.entryId
select new { rec.entryId, rec.year, rec.category }).ToList();
}