I have such a case study:
ToList() case:
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 case:
When I change in first query - List<CategoryType> to IQueryable<CategoryType> and remove ToList() from the end of query then I dont have any result:
Question:
I am asking for an explanation, I do not understand why this is happening. I know that the IQueryable makes some part of the work on the database side.
Edit: The code is working, pictures shows the final effect.
I have:
public IQueryable<CategoryType> CategoryTypePagination { get; set; }
and in the end of ToList() case:
this.CategoryTypePagination = categories.AsQueryable();
in IQueryable case just removed .AsQueryable()

