Filter IEnumerable against IEnumerable

前端 未结 4 990
轻奢々
轻奢々 2021-01-20 18:38

I have an object Style with a property StockNumber. I would like to filter a list of all Db.Styles against an IEnumerable

4条回答
  •  春和景丽
    2021-01-20 19:07

    You can think of Intersect as effectively a Join where the keys of each object are always "themselves". Here you want to perform a join where the key isn't always "itself", so you use a Join (or, if you need to remove duplicates, a GroupJoin).

    var query = from style in Db.Styles
        join number in stockNumbers
        on style.StockNumber equals number
        into numbers
        where numbers.Any()
        select style;
    

提交回复
热议问题