I have a table with a string/varchar property.
My method accepts a string, which can be a comma separated list.
My goal is to build a dynamic where clause that will loop through the comma separated list and make a where clause with my query but I'm not getting the syntax correct.
public async List<DataObj> GetData(string pets)
{
IQueryable<DataObj> query = dbSet;
if (!string.IsNullOrEmpty(pets))
{
var split = pets.Split(",");
foreach (var t in split)
{
query = query.Where(x => x.Pets.Contains(t.Trim()));
}
}
return await query.DataObj.AsNoTracking().ToListAsync();
}
So if DataObj.Pets for one record is "dog, cat". And DataObj.Pets for another record is: "dog, birds".
If I put in "birds" as the argument to the repo, it should return DataObj2, if I put in "dog", it should return both, and if I put in "dog, birds" the query should return both DataObj1 and DataObj2.
Is anything wrong with my query, because it's not doing that.