首页 > 解决方案 > 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()

标签: c#linqicollection

解决方案



推荐阅读