Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq结果基于内部列表中对象的属性_C#_Linq_Linq To Xml - Fatal编程技术网

C# Linq结果基于内部列表中对象的属性

C# Linq结果基于内部列表中对象的属性,c#,linq,linq-to-xml,C#,Linq,Linq To Xml,我尝试从以下xml中获得一些结果: <?xml version="1.0" encoding="utf-8" ?> <root> <Roles> <Role name="File Server"> <Image></Image> <AppToRun name="VM"> <AppOption name="KVM" value="FS-CentOS67" /

我尝试从以下xml中获得一些结果:

<?xml version="1.0" encoding="utf-8" ?>
<root>
  <Roles>
    <Role name="File Server">
      <Image></Image>
      <AppToRun name="VM">
        <AppOption name="KVM" value="FS-CentOS67" />
      </AppToRun>
    </Role>
    <Role name="VCS Gateway">
      <Image></Image>
      <AppToRun name="VCS_Server" dependentPC="FS" />
      <AppToRun name="SpeechGenerator" dependentPC="FS" />
    </Role>
    <Role name="Supervisor">
      <Image>LTInstructor.png</Image>
    </Role>
    <Role name="Ground Controller">
      <Image>Final.png</Image>
      <DependentRoles>
        <DependentRole name="File Server" />
        <DependentRole name="VCS Gateway" />
      </DependentRoles>
      <AppToRun name="VM" dependentPC="FS">
        <AppOption name="KVM" value="Tower1-CentOS67" />
      </AppToRun>
      <AppToRun name="VCS">
        <AppOption value="VCS-LC" />
        <AppOption value="VCS-GC" />
      </AppToRun>
      <AppToRun name="LXV" />
        <AppOption value="start_speech_controller_LCGC.bat" />
      </AppToRun>
    </Role>
    <Role name="Pilot 1">
      <Image>Pilot.jpg</Image>
      <DependentRoles>
        <DependentRole name="File Server" />
        <DependentRole name="VCS Gateway" />
        <DependentRole name="Ground Controller" />
      </DependentRoles>
      <AppToRun name="VM" dependentPC="FS">
        <!-- FS is defined in HOSTS file -->
        <AppOption name="KVM" value="Pilot1-CentOS67" />
        <AppOption name="KVM" value="Pilot2-CentOS67" />
      </AppToRun>
      <AppToRun name="VCS">
        <AppOption value="VCS-PP1" />
      </AppToRun>
    </Role>
  </Roles>
</root>
DependentRole

public class Role
{
    public string RoleName { get; set; }
    public string ImageName { get; set; }
    public List<DependentRole> DependentRoles { get; set; }
    public List<AppToRun> AppsToRun { get; set; }

    public Role()
    {
        if (AppsToRun == null)
            AppsToRun = new List<AppToRun>();

        if (DependentRoles == null)
            DependentRoles = new List<DependentRole>();
    }
}
public class DependentRole
{
    public string Name { get; set; }
}
我尝试了类似的方法,但返回的错误是“无法隐式转换类型”System.Collections.Generic.IEnumerable“为bool”

IEnumerable<DependentRole> r2 = Roles.Where(r => r.DependentRoles.Where(dr => dr.Name == roleName);
IEnumerable r2=Roles.Where(r=>r.DependentRoles.Where(dr=>dr.Name==roleName);
如何返回属性为指定值(在本例中为“Pilot 1”)的DependentRoles的列表

IEnumerable<DependentRole> r2 = Roles.SelectMany(r => r.DependentRoles.Where(dr => dr.Name == roleName));
IEnumerable r2=Roles.SelectMany(r=>r.DependentRoles.Where(dr=>dr.Name==roleName));

查看以了解详细信息

谢谢。我尝试了
。任何
,运气都不好,但不知何故没有看到
。选择了许多
。得到了我需要的结果。
IEnumerable<DependentRole> r2 = Roles.Where(r => r.DependentRoles.Where(dr => dr.Name == roleName);
IEnumerable<DependentRole> r2 = Roles.SelectMany(r => r.DependentRoles.Where(dr => dr.Name == roleName));