Performing part of a IQueryable query and deferring the rest to Linq for Objects

前端 未结 5 1047
温柔的废话
温柔的废话 2021-02-15 15:37

I have a Linq provider that sucessfully goes and gets data from my chosen datasource, but what I would like to do now that I have my filtered resultset, is allow Linq to Objects

5条回答
  •  野性不改
    2021-02-15 15:50

    Unless I'm misunderstanding, I generally just add .ToArray() in the chain of linq methods at the point where I want the linq provider to execute.

    For example (think Linq to SQL)

    var result = datacontext.Table
       .Where(x => x.Prop == val)
       .OrderBy(x => x.Prop2)
       .ToArray()
       .Select(x => new {CoolProperty = x.Prop, OtherProperty = x.Prop2});
    

    So through OrderBy() gets translated into SQL, but the Select() is LINQ to Objects.

提交回复
热议问题