I need to filter a list of both parent and child rows and return the parent object with the filtered child objects. This is from a shared library so cannot be an anonymous type (var)
I have a Parent object with Children (well, child objects). I want to return the parent object with parentId = 1 with a filtered set of child objects (itemType = 2).
Currently I'm using the AssociateWith DataLoadOptions method and this is working great. However, I was curious if there was an alternate way without using AssociateWith or if there was a better way in general.
Note: I need to return the parent object from the function. That is a requirement.
Shared.ModelDataContext dc = new Shared.ModelDataContext();
System.Data.Linq.DataLoadOptions dlo = new System.Data.Linq.DataLoadOptions();
dlo.AssociateWith<Shared.Parent>(p => p.Children.Where(c => c.itemType== 2));
dc.LoadOptions = dlo;
Shared.Parent parent = dc.Parents.Where(x => x.parentId == 1).First();
return parent;