选择IEnumerable< object>.来自IEnumerable< IEnumerable<对象>林克 [英] Select IEnumerable<object> from IEnumerable<IEnumerable<object>> linq
本文介绍了选择IEnumerable< object>.来自IEnumerable< IEnumerable<对象>林克的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要做的是选择嵌套元素列表,这是我的查询,returns
IEnumerable<IEnumerable<object>>
这是我的linq表达式:
What I need to do is select list of nested elements, here is my query which returns
IEnumerable<IEnumerable<object>>
here is my linq expression:
from a in (questions.Select(x => x.AnswerList).ToList())
select a.Select(x => x.AnswerBasicViewModel);
我该怎么做才能使其仅return
而不是IEnumerable<IEnumerable<object>>
?
How should I do that to make it return
only IEnumerable<object>
instead of IEnumerable<IEnumerable<object>>
?
在我的样本中请弄清楚,我想得到IEnumerable<AnswerBasicViewModel>
.
Just to be clear in my sample I would like to get IEnumerable<AnswerBasicViewModel>
.
推荐答案
使用SelectMany
运算符:
from q in questions
from a in q.AnswerList
select a.AnswerBasicViewModel
或者简单地
questions.SelectMany(q => q.AnswerList)
.Select(a => a.AnswerBasicViewModel)
这篇关于选择IEnumerable< object>.来自IEnumerable< IEnumerable<对象>林克的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文