Exemplo n.º 1
0
        private Expression VisitParameterInteral(ParameterExpression p, bool ignoreParamStack)
        {
            DbReference dbRef = null;

            if (p.Type.IsAnonymouse() || p.Type.IsGrouping())
            {
                var dbSelect = _state.GetLastSelect();
                dbRef             = _dbFactory.BuildRef(null);
                dbRef.OwnerSelect = dbSelect;

                var collection = p.Type.IsGrouping()
                    ? dbSelect.GroupBys.AsEnumerable()
                    : dbSelect.Selection;

                foreach (var selectable in collection)
                {
                    dbRef.RefSelection[selectable.GetAliasOrName()] = selectable;
                }
            }


            if (dbRef == null && !ignoreParamStack && _state.ParamterStack.Count > 0)
            {
                var dbRefs = _state.ParamterStack.Peek();
                if (dbRefs.ContainsKey(p))
                {
                    dbRef = dbRefs[p];
                }
            }

            // if we can not find the parameter expression in the ParamterStack,
            // it means this is the first time we translates the parameter, so we
            // need to look for it in the most recently translated select
            // this is required because we may not always has select on the top
            // of the stack, especially we translating arguments for method calls
            if (dbRef == null)
            {
                var dbSelect = _state.GetLastSelect();

                var refCol = (_state.ResultStack.Peek() as IDbRefColumn) ??
                             dbSelect.Selection.OfType <IDbRefColumn>().LastOrDefault();

                dbRef = refCol != null ? refCol.Ref : dbSelect.From;
            }

            if (dbRef == null)
            {
                throw new NullReferenceException();
            }

            _state.ResultStack.Push(dbRef);

            return(p);
        }
Exemplo n.º 2
0
 internal IDbSelect GetSelect()
 {
     return(_state.GetLastSelect());
 }