为什么在CompensatingCollection上调用IQueryable方法会抛出System.NotSupportedException

时间:2018-06-18 11:30:25

标签: c# .net entity-framework

我的查询看起来像这样:

result = (from tbl1 in dbcontext.table1
         join tbl2 in dbcontext.table2 on tbl1.field equals tbl2.field
         group tbl1 by tbl1.Id into gr
         select new
         {
             prop1 = gr.Key,
             prop2 = dbcontext.table1.Where(t => ...).Select(t => ...)
         }).ToList()

此查询可能会返回大量数据,因此我的目的是通过获取prop1来缩小尺寸,并将prop2存储为IQueryable,以便稍后在需要时调用。

但是在运行时,我可以在prop2上调用的唯一方法是.ToList()。其他所有方法(如.First().Take())都会引发异常:

  

“对于具体化的查询结果,不支持此方法。”

调试显示prop2是一种类型:

  

System.Linq.IQueryable<> {System.Data.Entity.Core.Common.Internal.Materialization.CompensatingCollection<>}

我的问题是为什么我无法在此IQueryable上调用CompensatingCollection方法?

CompensatingCollection班是什么?我发现的唯一一件事是source code,但仍然无法理解它是什么。

0 个答案:

没有答案