I have an object Style
with a property StockNumber
. I would like to filter a list of all Db.Styles
against an IEnumerable<string> stockNumbers
the user enters in a search. DB.Styles
is an IEnumerable<Style>
. Here is essentially what I am trying to do:
public IEnumerable<Style> LoadListOfStyles(IEnumerable<string> stockNumbers)
{
return Db.Styles.Intersect(stockNumbers);
// Need to filter Db.Styles based on stockNumbers
}
So is there an easy way to compare the list of all styles in Db.Styles
against my search values in stockNumbers
to return a filtered list of only the Styles
the user has searched for? The only way I have seen to be able to do this is to have 2 IEnumerable objects to intersect, but loading the styles one by one from the stock numbers searched seems like a lot of unnecessary code. I am wondering if there is an easier way. Or do I need to roll my own method to filter the results?