Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.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 - Fatal编程技术网

C# 第三个子级别上的Linq查询

C# 第三个子级别上的Linq查询,c#,linq,C#,Linq,我对物品清单有以下要求。 我的班级结构如下: public class Standard { public long Id {get;set;} public string Name {get;set;} public List<Student> Students {get;set;} } public class Student { public long Id {get;set;} public

我对物品清单有以下要求。 我的班级结构如下:

  public class Standard
    {
    public long Id {get;set;}
    public string Name {get;set;}
    public List<Student> Students {get;set;}
    }
    
    public class Student
    {
    public long Id {get;set;}
    public string Name {get;set;}
    public List<Hobby> Hobbies {get;set;}
    }
    
    public class Hobby
    {
    public long Id {get;set;}
    public string Name {get;set;}  
    }
公共类标准
{
公共长Id{get;set;}
公共字符串名称{get;set;}
公共列表学生{get;set;}
}
公立班学生
{
公共长Id{get;set;}
公共字符串名称{get;set;}
公共列表爱好{get;set;}
}
公共课爱好
{
公共长Id{get;set;}
公共字符串名称{get;set;}
}
我想根据以下场景中的爱好进行筛选:

  • 有音乐爱好的学生的所有标准列表
  • 有唱歌爱好的学生的所有标准列表
目前我有一份清单,上面有所有的子类和详细信息。我可以用ForEach循环实现这一点,但我想学习这个场景的Linq语法


请为此建议Linq语法。

鉴于您有一个名为
标准的
标准的集合

有音乐爱好的学生的所有标准列表

有唱歌爱好的学生的所有标准列表


感谢您的帮助,但是嗜好也有类结构,如Hobby.Id和Hobby.Nameswap
u.cabbies.Contains
u.cabbies.Where(h=>h.Name==“Singing Songs”)
只要做
u.cabbies.Any(h=>h.Name==“Playing Music”)
而不是Contains。
var result = standards.Where(s => s.Students.Any(u => u.Hobbies.Any(h => h.Name == "Playing Music")));
var result = standards.Where(s => s.Students.Any(u => u.Hobbies.Any(h => h.Name == "Playing Music")));