I am trying to use this answer to dynamically add an OR operator to the WHERE clause in LINQ: https://stackoverflow.com/a/782350/1316683
var searchPredicate = PredicateBuilder.False<Songs>();
foreach(string str in strArray)
{
var closureVariable = str;
searchPredicate =
searchPredicate.Or(SongsVar => SongsVar.Tags.Contains(closureVariable));
}
var allSongMatches = db.Songs.Where(searchPredicate);
In my case Tags is a List<Tag>, not a property, I would like to do something like this:
searchPredicate.Or(SongsVar => SongsVar.Tags.Any().TagName.Contains(closureVariable));
Then I thought of something like this, which doesn't work:
searchPredicate.Or(x => x.Tags.Where(p => p.TagName.Contains(closureVariable )).Count() > 0);
Is this possible?