c# - IQueryable 与 ICollection(列表)
问题描述
我有这样一个案例研究:
ToList()
案子:
List<CategoryType> categories = (from c in categoryTypes where c.IsSysParam == isSysParamCategory select new CategoryType { Code = c.Code, CreateDate = c.CreateDate, EditDate = c.EditDate, IsProductCategory = c.IsProductCategory, IsSysParam = c.IsSysParam, Name = c.Name, TypeId = c.TypeId, ValueTypes = new List<ValueType>() }).ToList();
List<ValueType> valueTypeList = new List<ValueType>();
foreach (var c in categories.ToList())
{
valueTypeList = categoryTypes.Where(x => x.TypeId == c.TypeId).SelectMany(v => v.ValueTypes).Where(v => v.ParentValueId == null).ToList();
c.ValueTypes = valueTypeList;
}
IQueryable
案子:
当我在第一个查询中更改 -List<CategoryType>
到查询末尾IQueryable<CategoryType>
并从查询末尾删除ToList()
时,我没有任何结果:
问题:
我要求解释,我不明白为什么会这样。我知道这IQueryable
在数据库方面做了一些工作。
编辑: 代码正在运行,图片显示了最终效果。
我有:
public IQueryable<CategoryType> CategoryTypePagination { get; set; }
最后ToList()
:
this.CategoryTypePagination = categories.AsQueryable();
万一IQueryable
刚刚删除.AsQueryable()
解决方案
您必须查看“延迟查询执行”和“立即查询执行”
推荐阅读
- regex - 正则表达式将数字模式与旋转匹配
- python - Django - 将查询结果打印到 html
- javascript - Wrap every character of a timestamp in `` element
- c# - C# 对多个结构进行分组并传递给函数参数?
- mysql - 为什么我收到错误:错误 1822:无法添加外键约束?引用表中缺少约束 XXXX 的索引?
- r - 逐行创建 R 数据框
- c# - 在 Windows 10 上使用纯 C# 导入或注册 Hyper-v VM
- python - 在 Python 中创建 CAT 程序
- flutter - 如何在 Flutter Web 中知道使用 PWA 或桌面的用户?
- angular - Angular:在拦截器中添加不记名令牌