简体   繁体   English

C# LINQ 过滤器深层嵌套列表

[英]C# LINQ Filter deep nested list

I've a structure based of list containing other list.我有一个基于包含其他列表的列表的结构。 I need to filter the list based on the value of a property based in the deepest part of the list.我需要根据列表最深处的属性值过滤列表。

Right now I'm doing this:现在我正在这样做:

queryable = queryable
    .Include(x => x.Carriers)
    .ThenInclude(c => c.CarrierActions)
    .ThenInclude(ca => ca.Action)
    .ThenInclude(ac => ac.ActionFacts);

queryable = queryable
    .Where(x => x.Carriers.Any(
        carriers => carriers.CarrierActions.Any(
            carrieractions =>
                carrieractions.Action.ActionTypeId ==
                ActionTypeEnum.DosemeterCalculateDeepDose)));

I join the needed tables, then I filter them based on the ActionTypeId based 3 levels below the top list.我加入所需的表,然后根据顶部列表下方 3 个级别的 ActionTypeId 过滤它们。

First off all, is it possible to do this in 1 step ( include the filtering with the joins ), second of all, the second part is not working as my list gets empty, but I'm certain that actions with that type get values.首先,是否可以在 1 个步骤中执行此操作(包括使用连接进行过滤),其次,第二部分不起作用,因为我的列表变空了,但我确定该类型的操作会获得值.

Using .NET Core 2.0.3 btw!顺便说一句,使用 .NET Core 2.0.3!

To answer your first part, you can do this要回答你的第一部分,你可以这样做

queryable = queryable
    .Include(x => x.Carriers)
    .ThenInclude(c => c.CarrierActions)
    .ThenInclude(ca => ca.Action)
    .ThenInclude(ac => ac.ActionFacts)
    .Where(x => x.Carriers.Any(
        carriers => carriers.CarrierActions.Any(
            carrieractions =>
                carrieractions.Action.ActionTypeId ==
                ActionTypeEnum.DosemeterCalculateDeepDose)))

To your second part, it should be working, id check your data, as this is pretty straight forward对于您的第二部分,它应该可以正常工作,请检查您的数据,因为这非常简单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM