I would like to find out, if a string (stored in Column OSchlagwoerter in the database) contains any string within a list of strings (stored in variable tags).
In order to achieve this, I want to loop through the list of tags and check for each tag if OSchlagwoerter contains it. However, I cannot access the field OSchlagwoerter of the object passed.
The database query looks like this
return dbctx.Images
.Where(tagFilter(tags))
.Select(x => new ImageObj()
.ToList();
The tagFilter
Expression should look like this:
private Expression<Func<ImageObj, bool>> tagFilter(List<string> tags)
{
if ( tags.Count > 0)
{
//This line does not work
var tagsInDb = x => x.OSchlagwoerter;
foreach (var t in tags)
{
if (tagsInDb .Contains(t))
{
return true;
}
}
return false;
//first approach, does not work, only finds one tag in columns with on word in it
//return x => tags.Contains(x.OSchlagwoerter);
}
else
{
return x => true;
}
}