1

使用 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));

我有一组表 Parent -> Child -> Grandchild -> Great-Grandchild

我尝试使用 RecordId、ParentId、ChildRecords 属性无济于事。此外,我所有的课程都用 [BindChildren(BindChildrenFor.All)] 装饰。

有没有办法让我的曾孙子孙满堂?谢谢!

4

1 回答 1

3

该模式类似于孙子。对于父母:选择器,您只需要使用 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));

);

于 2015-03-13T12:32:14.950 回答