使用Insight.Database,我可以查询包含子项及其孙子的对象:
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));
我有一组表格 家长 - &gt;孩子 - &gt;孙子 - &gt;曾孙
我尝试使用RecordId,ParentId,ChildRecords属性无济于事。另外,我的所有课程都用[BindChildren(BindChildrenFor.All)]装饰。
我有没有办法让大孙子们居住?谢谢!
答案 0 :(得分:2)
这种模式与孙子孙女相似。对于parent:selector,你只需要使用SelectMany来获取孙子的完整列表。
(至少,它应该如何运作......)
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));
);