score:0

no, each query is executed independently, and all you're left with is the result set of the query itself. there is nothing within the memory object that contains the original collection nor any accessible reference to the original collection. considering that the original collection may now be null or out of scope, this would be dangerous to allow even. if you need to the original collection, you will need to keep it in scope until you're completely finished with it.

score:0

this is cheating, but maybe it makes sense in your context:

interface ireferencedqueryable<t> : iqueryable<t>
{
    ienumerable<t> source { get; }
}

static class ireferencedqueryableextensions
{
    public static ireferencedqueryable<t> asreferencedqueryable<t>(
        this ienumerable<t> source)
    {
        return referencedqueryable.from(source);
    }

    class referencedqueryable<t> : ireferencedqueryable<t>
    {
        public ienumerable<t> source { get; private set; }

        referencedqueryable(ienumerable<t> source)
        {
            source = source;
        }

        static ireferencedqueryable<t> from(ienumerable<t> source)
        {
            return new referencedqueryable(source);
        }

        // all the iqueryable members would be 
        // implemented through asqueryable()
        // ...
    }

    public static ireferencedqueryable<t> where<t>(
        this ireferencedqueryable<t> source, 
        expression<func<t, bool>> predicate)
    {
        return referencedqueryable.from(
            ((iqueryable<t>)source).where(predicate));
    }

    // do the same for all the linq extension methos you want to support
}

you would use it like this:

t[] itemarray = // initialized values
var itemquery = itemarray.asreferencedqueryable()
                         .where(*/some query*/)
                         .skip(5)
                         .etc() ...

when you need your source sequence you can access it through the source member, possibly through an as cast.

var s = itemquery.source;

score:3

the iqueryable most likely does have a reference to the underlying collection (possibly through a number of layers of indirection), but it won't be publicly exposed, so you won't be able to access it, at least not in any way that i would consider reasonable and not a very, very messy hack.


Related Query

More Query from same tag