How do i do this in LINQ – So i dont have to use ForEach or loops?
I can’t seem to figure out how to pass a list when some condition is met and this way loop the collection with LINQ.
products.ForEach(delegate(CustomEcomProducts p)
{
p.VariantProducts = variants.Where(prod => prod.VariantParentID == p.ProductID)
.ToList();
});
That’s not what LINQ is for. The Q in LINQ stands for “Query”.
The best/cleanest/most readable way to do this is the following: