执行的IQueryable查询的一部分,并推迟休息到LINQ的对象 [英] Performing part of a IQueryable query and deferring the rest to Linq for Objects

查看:111
本文介绍了执行的IQueryable查询的一部分,并推迟休息到LINQ的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个LINQ提供程序成功地去和我所选择的数据源获取数据,但我想现在我有我的过滤结果集做什么,就是让LINQ到对象来处理表达式树的其余部分(东西像加入,投影等)

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 to process the rest of the Expression tree (for things like Joins, projection etc)

我的想法是,我可以只替换包含我IQueryProvider通过一个ExpressionVisitor结果集的IEnumerable表达不变,然后返回新表达。另外从我的IQueryable返回了IEnumerable的供应商...但是这似乎并没有工作: - ?(

My thought was that I could just replace the expression constant that contains my IQueryProvider with the result-sets IEnumerable via an ExpressionVisitor and then return that new expression. Also return the IEnumerable's provider from my IQueryable...but this does not seem to work :-(

任何想法的

编辑:
这里有一些很好的答案,但鉴于表...

Some good answers here, but given the form...

var qry = from c in MyProv.Table<Customer>()
          Join o in MyProv.Table<Order>() on c.OrderID equals o.ID
          select new 
          {
            CustID = c.ID,
            OrderID = o.ID
          }

在我的供应商我可以很容易地回到客户和订单的2结果集,如果数据是从SQL源,我只想建设,并通过对SQL连接语法,但这种情况下,数据是不是从一个SQL源,所以我需要做的在加入代码...但正如我说我有2结果集,和LINQ到对象可以做一个加入...(以及后来的投影)这将是真正的好,只是代替常量表达式 MyProv.Table<客户> MyProv.Table<排序> 列表<客户> 列表<排序> 而让列表与LT;> 提供商过程中的表达是......可能?如何

In my provider I can easily get back the 2 resultsets from Customers and Orders, if the data was from a SQL source I would just construct and pass on the SQL Join syntax, but it this case the data is not from a SQL source so I need to do the join in code...but as I said I have the 2 result sets, and Linq to Objects can do a join...(and later the projection) it would be real nice to just substitute the Expression constants MyProv.Table<Customer> and MyProv.Table<Order> with List<Customer> and List<Order> and let a List<> provider process the expression...is that possible? how?

推荐答案

那种东西,我是后更换可查询<?>常量表达式树一个具体的IEnumerable (或IQueryable的通过.AsQueryable())结果集...这是一个复杂的话题,恐怕只有让任何意义LINQ提供程序的作家谁是膝盖深的表达式树的游客等。

The kind of thing that I was after was replacing the Queryable<> constant in the expression tree with a concrete IEnumerable (or IQueryable via .AsQueryable()) result set...this is a complex topic that probably only makes any sense to Linq Provider writers who are knee deep in expression tree visitors etc.

我发现在MSDN演练,做的东西像什么我是后一个片段,这给了我前进的道路...

I found a snippet on the msdn walkthrough that does something like what I am after, this gives me a way forward...

using System;
using System.Linq;
using System.Linq.Expressions;

namespace LinqToTerraServerProvider
{
    internal class ExpressionTreeModifier : ExpressionVisitor
    {
        private IQueryable<Place> queryablePlaces;

        internal ExpressionTreeModifier(IQueryable<Place> places)
        {
            this.queryablePlaces = places;
        }

        internal Expression CopyAndModify(Expression expression)
        {
            return this.Visit(expression);
        }

        protected override Expression VisitConstant(ConstantExpression c)
        {
            // Replace the constant QueryableTerraServerData arg with the queryable Place collection.
            if (c.Type == typeof(QueryableTerraServerData<Place>))
                return Expression.Constant(this.queryablePlaces);
            else
                return c;
        }
    }
}

这篇关于执行的IQueryable查询的一部分,并推迟休息到LINQ的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆