c# - Filter items based on an IEnumerable -


I have a list of objects that have a property (product name) that is a IEnumberable & lt; String & gt; . How can I filter this list on the property, so that I only get a list where the item is another IEnumerable & lt; String & gt; (FilterProductNames) matches all the items?

I have tried the following, but it seems that all the items that match anything in the IEnumberable filter matches one match (one or a style match):

  Items Where (x => x.ProductNames.Intersect (FilterProductNames) Anyone ())   

UPDATE

have tried to use the answers but I think that should give me an empty set is just one item in FilterProductNames but it still did not give me anything, so I tested the same filter by doing the following: < / P>

  if (count == 1) {// it will return me item 4 item = item Where (x => x.ProductNames.Contains (FilterProductNames.First ())); } Else {// When I remove the above, it will only filter items on the same item item item = item. Where (x => x.ProductNames.All (pn = & gt; filterprintnet.source (pn))); // has tried another version of Tim's reply but no profit: // item = item Where (x => X.ProductNames.Except (FilterProductNames) .no ()); Sorry for the bad words that caused some confusion, I am after those items that put all names in the filter product names.   

UPDATE 2 but are not only limited to the items in FilterProductNames therefore extend For example, if I search for items that have Test and Test There are product names of 1, then any item should be brought back which includes both names along with that name

Is it possible?

You Enumerable.All :

  Items Where (x = & gt; x.ProductNames.All (pn = & gt; Filtrprentnnamksnsadn (pn)))   

or - probably more efficient - ! ... except. Anyone :

  items. Where (x => X.ProductNames.Except (FilterProductNames) .no ()); Your comment / edit:  "... all items containing filter names include all names"  Em>  

Then you have to return the statement:

  items. Where (x = & amp; ;; Filter ProductName All (FP = & gt; x.ProductNames.Contains (fp)));   

or

  items. Where (x = & gt;! Filter ProductName; Leave (x.ProductNames) .no ());    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -