3

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);

How should I do that to make it return only IEnumerable<object> instead of IEnumerable<IEnumerable<object>>?

Just to be clear in my sample I would like to get IEnumerable<AnswerBasicViewModel>.


Auto generate registration code in custom format

Hi I'm new in PHP need some help, i want to generate auto registration code like this (e.g: 0001, 0002, ..) form data base if available in database auto plus one in last number if not start from 0000 it go at 9999 and stop

my sql table as

id | regisCode | title

query is

$query = mysql_query("Select * from accounts");
$result = mysql_num_rows($query);
if ($result >  0){

$row = mysql_fetch_array ($result);
} else{
$new = 0000;
}

$account = substr('0000', 1);

$faccount = 1+$account;


echo "<h1>". $faccount ."</h1>";

sorry for poor english

4

2 回答 2

8

使用SelectMany运算符:

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

或者干脆

questions.SelectMany(q => q.AnswerList)
         .Select(a => a.AnswerBasicViewModel)
于 2013-09-13T10:06:50.130 回答
3

SelectMany 是去这里的方式:

questions.SelectMany(x => x.AnswerList).Select(x => x.AnswerBasicViewModel);
于 2013-09-13T10:07:44.003 回答