我想根据父母过滤孙子。我不确定在使用 ThenInclude 时如何引用回父级。
如果父母存在这种情况,我只想带入已加入的孙子。
想要做这样的事情,我只是不确定如何引用回父属性。
_context.Parent.Include(w => w.Child)
.ThenInclude(t => t.Grandchild.Where(g => g.Conditions.Any(c => c.Condition.Contains('I want to reference back to parent or child to filter here')))
这可能吗?是否可以使用查询语法而不是方法语法?
是的,这是完全可能的。刚刚用回了父 lambda。
假设一位父母只有一个孩子,一位孩子只有一个孙子:
_context.Parent.Include(w => w.Child)
.ThenInclude(t => t.Grandchild.Where(g => g.Conditions.Any(c => c.Condition.Contains(
_context.Parent.Single(h => h.Child.Grandchild == g).parentProps
)))