我有以下json
{
"name":"Student",
"Classes" : ["Chemistry","Math","Algebra"]
}
以及以下poco
public class Studen
{
public string Name {get;set;}
public string[] Classes {get; set;}
}
我想查询一个特定班级的特定学生(比如数学),并且poco在数组中有一个单项,即“Math”字符串
答案 0 :(得分:2)
如果您的集合是变量集合:
collection.Find(x => x.Classes.Contains("Math"))
.Project(s =>
new Student {
Name = s.Name,
Classes = s.Classes.Where(c=>c=="Math").ToArray()})
.ToList();