I have 3 levels of lists one inside other as below
ProductResults
ErrorNo
ErrorString
Products
ProductNo
ProductName
SVNID
ProductOrders
OrderNo
DateOfOrder
UDEID
I want to check the value of UDEID in the lowest list. If the value is 77 then I want to update the SVNID in the Products list above. How can I achieve this? I have tried below
ProductResultsList.Where(x => x.Products.Any(y => y.ProductOrders.Any(z => z.UDEID == 77))).ToList().
ForEach(u =>
{
u.Products.ForEach(v => v.SVNID = 90);
});
My data
ProductResultsList.ErrorNo = 0
ProductResultsList.ErrorString = ""
ProductResultsList.Products[0].ProductNo = "XY6789U"
ProductResultsList.Products[0].ProductName = "OrangeJuice"
ProductResultsList.Products[0].SVNID = 100
ProductResultsList.Products[0].ProductOrders[0].OrderNo = 201
ProductResultsList.Products[0].ProductOrders[0].DateOfOrder = 28/09
ProductResultsList.Products[0].ProductOrders[0].UDEID = 77
ProductResultsList.Products[1].ProductNo = "XY4569U"
ProductResultsList.Products[1].ProductName = "AppleJuice"
ProductResultsList.Products[1].SVNID = 100
ProductResultsList.Products[1].ProductOrders[0].OrderNo = 202
ProductResultsList.Products[1].ProductOrders[0].DateOfOrder = 28/09
ProductResultsList.Products[1].ProductOrders[0].UDEID = 88
The problem with the above is that it updates all Products.SVNID to 90. I just want to update Products[0] and not Products[1]. I do understand why its happening because my ForEach is ProductResults but then I don't know how to do what I want.
Please help
u.Products[0].SVNID = 90;instead ofu.Products.ForEach(v => v.SVNID = 90);ForEachis not a part of Linq, so you are using Linq (for example theWhereandAnycalls, but your solution might not involve Linq.).