Using Insight.Database, I can query for an object with children and its grandchildren:
var someObject = connection.Query("SomeStoredProc", new {ParentId = id}, Query.Returns(Some<Parent>.Records)
.ThenChildren(Some<Child>.Records)
.ThenChildren(Some<Grandchild>.Records,
parents: parent=> parent.Children,
into: (child, grandchildren) => child.Grandchildren = grandchildren));
I have a set of tables Parent -> Child -> Grandchild -> Great-Grandchild
I tried using RecordId, ParentId, ChildRecords attribute to no avail. Also, all my classes are decorated with [BindChildren(BindChildrenFor.All)].
Is there a way I have the populate the Great-Grandchildren? Thanks!
The pattern is similar to grandchildren. For the parents: selector, you just need to use a SelectMany to get the full list of grandchildren.
(At least, that's how it's supposed to work...)
var someObject = connection.Query("SomeStoredProc", new {ParentId = id},
Query.Returns(Some<Parent>.Records)
.ThenChildren(Some<Child>.Records)
.ThenChildren(Some<Grandchild>.Records,
parents: parent=> parent.Children,
into: (child, grandchildren) => child.Grandchildren = grandchildren)
.ThenChildren(Some<GreatGrandchild>.Records,
parents: parent=> parent.Children.SelectMany(c => c.Grandchildren)),
into: (grandchild, greatgrantchildren) => grandchild.greatgrantchildren= greatgrantchildren));
);