【发布时间】:2019-09-05 06:24:00
【问题描述】:
我有一个模型,其字段具有引用同一类的成员变量。现在我想查询数据及其子项,但我只想输出某些成员并过滤其他成员。
示例模型:
public class ContentModel
{
public string Name;
public string Url;
public string x, y, z // filter this
public IEnumerable<ContentModel> Children;
}
预期输出:
{
"Name": "",
"Url": "",
"Child": {
"Name": "",
"Url": "",
"Child": {
"Name": "",
"Url": ""
}
}
}
【问题讨论】:
-
请分享您尝试过的内容以及包含列表本身的代码。通常使用
.Select完成预测 -
孩子不应该是一个列表对象还是只是一个孩子?模型不是分层的。它们采用表格格式,因此您需要递归地获取每个层次结构。我会在样品上炒锅。
-
应该是一个 IEnumerable
Children;