【发布时间】:2012-06-08 15:30:27
【问题描述】:
我有以下 LINQ 语句:
var query =(from item in _itemRepository.FindAll()
where item.Id == "20649458"
from singelitem in item.ListOfChildren
where singelitem.Property == "singelitem"
from manyitems in item.ListOfChildren
where manyitems.Property == "many"
select new
{
item.Id,
singelitem,
manyitems
});
var result = query.ToList();
Tasks 是对象的集合,where 子句tasks.Property == "something" 匹配集合中的多个项目,但是当我在选择中使用匿名类型时,我只取回匹配结果的一个项目(第一个)而不是一个集合任务。如何取回集合中的所有匹配任务?
编辑: 真正发生的是我得到了平面对象(就像来自连接语句的数据库结果集)。
【问题讨论】:
-
使用
ToList();扩展方法实现结果集合。
标签: c# linq entity-framework anonymous-types