当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Select and WHERE using LINQ

问题描述:

I have following classes:

public class CatalogResponseRootObject

{

public Plans Plans { get; set; }

}

public class Plans

{

public List<Plan> plan { get; set; }

}

public class Plan

{

public List<PlanPackage> Packages { get; set; }

}

public class PlanPackage

{

public List<Package2> Package { get; set; }

}

public class Package2

{

public string Name { get; set; }

}

I have a working query. But Now I am trying use Where clause to get list of thosecPlans WHERE Package2.Name == "Annual". Is it possible to retrieve such information using the Where clause and how?

CatalogResponseRootObject catalogResponse = response;

qualifiedPlans = (from cPlans in catalogResponse.Plans.plan

join qPlans in conversationIDResponsePlans.plan on cPlans.Id equals qPlans.Id

select cPlans).ToList();

网友答案:

So plans have packages that have packages and there should be at least one that has the Name "Annual"? You can add a condition:

where cPlans.Packages.Any(p1 => p1.Package.Any(p2 => p2.Name == "Annual"))

This will return the plans that have at least one package with at least one package that has the name "Annual".

分享给朋友:
您可能感兴趣的文章:
随机阅读: