假设我有这个IQueryable变量:
var result= (from fruit in fruitTable
join dapple in applesIQuery on fruit.fruitType equals dapple.fruitType into apples
from apple in apples.DefaultIfEmpty()
select new foo );applesIQuery来自另一个由另一组IQueryable组成的joins。
applesIQuery =(from a in anotherTable select new {id = foo}) ;我需要处理applesIQuery == null的情况,基本上使用id=0创建一个包含1个元素的列表,但不将IQueryable转换为IEnumerable。类似于:
applesIQuery =(from a in anotherTable select new {id = foo})?? Iqueriable {new {id=0}} ;对正确的方向有什么建议吗?
发布于 2013-03-27 05:39:24
applesIQuery的类型为IQueryable,并且不会为null。假设您的意思是,如果查询没有返回任何结果,请尝试如下所示:
applesIQuery = applesIQuery.Count() == 0 ? new ArrayList(){ new { id = 0 } }.AsQueryable() : applesIQuery;https://stackoverflow.com/questions/15612104
复制相似问题