How to dynamically add OR operator to WHERE clause in LINQ

后端 未结 4 791
花落未央
花落未央 2020-11-30 07:36

I have a variable size array of strings, and I am trying to programatically loop through the array and match all the rows in a table where the column \"Tags\" contains at le

4条回答
  •  萌比男神i
    2020-11-30 07:56

    Either build an Expression yourself, or look at a different route.

    Assuming possibleTags is a collection of tags, you can make use of a closure and a join to find matches. This should find any songs with at least one tag in possibleTags:

    allSongMatches = allSongMatches.Where(s => (select t from s.Tags
                                                join tt from possibleTags
                                                    on t == tt
                                                select t).Count() > 0)
    

提交回复
热议问题