I am trying to query a comma delimited string using PredicateBuilder. My data set has DAYS in TR format which means Tuesday and Thursday, but my parameter query string will be passed in this way: Day=T,R. My query does not return any data right now so I guess have to use like '%' to get data. Can anyone tell me where the problem is in my linq query below:
public List<myTable> Get(string filter1 = null, string Day = null)
{
if (string.IsNullOrWhiteSpace(filter1) && string.IsNullOrWhiteSpace(Day) )
return new List<myTable>();
IQueryable<myTable> qry = db.myTable.AsQueryable();
var searchPredicate = PredicateBuilder.True<myTable>();
if (filter1 !=null){
searchPredicate = searchPredicate.And(a => a.Column1.Contains(filter1)
}
if (Day != null)
{
//split day string
string[] items = Day.Split(',');
foreach (var item in items)
{
searchPredicate = searchPredicate.And(a => items.Contains("%" + a.DAYS + "%"));
}
}
return qry.where(searchPredicate).ToList();
}
Or, how to create a where Predicate like this: where column1='filter' and (DAYS like 'T%' or DAYS like 'M%') ? Thanks.