Entity framework. Need help filtering results

后端 未结 3 604
傲寒
傲寒 2021-01-21 15:46

Need to select data in entity framework but need to filter on the childrent and grandchildren

i have 4 tables. Parent -> Child -> GrandChild -> GreatGran

3条回答
  •  离开以前
    2021-01-21 16:25

    This query should do what you want. Yes, it is a bit of a mess because it is so deeply nested.

    var result = context.Parent
                        .Where(parent => parent.Child
                                               .Any(child => (child.Column5 == 600) &&
                                                              child.GrandChild
                                                                   .Any(grandchild => grandchild.GreatGrandChild
                                                                                                .Any(greatgrandchild => greatgrandchild.Column3 == 1000))));
    

提交回复
热议问题