问题很混乱,但如下面的代码所述,它更加清晰:
List<List<T>> listOfList;
// add three lists of List<T> to listOfList, for example
/* listOfList = new {
{ 1, 2, 3}, // list 1 of 1, 3, and 3
{ 4, 5, 6}, // list 2
{ 7, 8, 9} // list 3
};
*/
List<T> list = null;
// how to merger all the items in listOfList to list?
// { 1, 2, 3, 4, 5, 6, 7, 8, 9 } // one list
// list = ??? …Run Code Online (Sandbox Code Playgroud) 我需要帮助以从linq查询中获取价值。使用firstordefault()
var item = (from o in db.Employee
join a in db.EmployeeLineManager on o.Id equals a.EmployeeID
where o.Id == Id
select new
{
AddedBy = o.LastName + " " + o.FirstName,
LineManagerId = a.LineManagerId,
Email = o.Email
}).FirstOrDefault();
Run Code Online (Sandbox Code Playgroud)
我可以获取项目中的内容(例如,如果我想获取电子邮件,可以使用item.Email)
但是,如果我使用ToList()
var item = (from o in db.Employee
join a in db.EmployeeLineManager on o.Id equals a.EmployeeID
where o.Id == Id
select new
{
AddedBy = o.LastName + " " + o.FirstName,
LineManagerId = a.LineManagerId,
Email = o.Email
}).ToList();
Run Code Online (Sandbox Code Playgroud)
我如何从商品中获取价值(例如,我想获取电子邮件,item.Email不起作用,请问我可以用什么来获取价值?