Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Using LINQ, how do I look at List that is contained in another object/List?

Say I have IEnumOfFood that contains a food object that lists out each ingredient. So something like IEnumOfFood[0] would be {‘Celery’, ‘Onion’, ‘Chicken’, [Stock]}. In this case, [Stock] is another IEnumerable. I’m trying to get each element in IEnumOfFood where Stock.Herb == "Bay Leaf".
It seems that no matter how I try and reword the LINQ query it always has some sort of error. Currently I have this:

IEnumOfFood= IEnumFoodItems.Select(x => x.Select(
y => y.Stock.Where(
y => y.Herb == "BayLeaf")));

Which throws a ‘Cannot convert lambda expression to type ‘bool’ because it is not a delegate type’.
This is just one of the many ways I’ve tried to get an element of IEnumOfFood where the Stock Enum has herb as ‘Bay Leaf’, I’m not saying this is what should work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Have you tryed:

IEnumFoodItems.Where(x => x.Any(s => s.Stock.Any(h => h.Herb == "BayLeaf")))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading