从 IEnumerable> linq 中选择 IEnumerable
2023-12-14

我需要做的是选择嵌套元素列表,这是我的查询returns IEnumerable<IEnumerable<object>>这是我的 linq 表达式:

from a in (questions.Select(x => x.AnswerList).ToList())
                           select a.Select(x => x.AnswerBasicViewModel);

我该怎么做才能做到return only IEnumerable<object>代替IEnumerable<IEnumerable<object>>?

只是为了在我的样本中清楚地表明我想得到IEnumerable<AnswerBasicViewModel>.


Use SelectMany操作员:

from q in questions
from a in q.AnswerList
select a.AnswerBasicViewModel

或者简单地

questions.SelectMany(q => q.AnswerList)
         .Select(a => a.AnswerBasicViewModel)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

从 IEnumerable> linq 中选择 IEnumerable 的相关文章