private OutputColumnDescriptor ResolveColumnReferenceCore(ColumnReferenceExpression node)
        {
            if (node.ColumnType != ColumnType.Regular)
            {
                throw new NotImplementedException(node.AsText());
            }

            if (node.MultiPartIdentifier.Count == 2)
            {
                // source (table/view) name without schema or alias
                string sourceNameOrAlias = node.MultiPartIdentifier[0].Dequote();
                string columnName        = node.MultiPartIdentifier[1].Dequote();

                return(TryResolveColumnReferenceCoreSN(node, sourceNameOrAlias, columnName));
            }
            else if (node.MultiPartIdentifier.Count == 1)
            {
                // no source only column name => traverse all source and find t
                string columnName = node.MultiPartIdentifier[0].Dequote();
                return(TryResolveColumnReferenceCoreSN(node, null, columnName));
            }
            else
            {
                // 3 or 4
                throw new NotImplementedException(node.AsText() + "   ## " + statement.WhatIsThis());
            }


            //return null;
        }
        private bool TryColumnReference(IQueryModel model, ColumnReferenceExpression node, out QueryColumnBase col)
        {
            if (node.ColumnType != ColumnType.Regular)
            {
                throw new NotImplementedException(node.AsText());
            }

            if (node.MultiPartIdentifier.Count == 2)
            {
                // source (table/view) name without schema or alias
                string sourceNameOrAlias = node.MultiPartIdentifier[0].Dequote();
                string columnName        = node.MultiPartIdentifier[1].Dequote();

                if (model.TryGetQueryOutputColumnByName(this.batchResolver, columnName, out col))
                {
                    return(true);
                }
                else
                {
                    throw new NotImplementedException(node.WhatIsThis()); // not resolved?
                }
            }
            else if (node.MultiPartIdentifier.Count == 1)
            {
                // no source only column name => traverse all source and find t
                string columnName = node.MultiPartIdentifier[0].Dequote();
                if (model.TryGetQueryOutputColumnByName(this.batchResolver, columnName, out col))
                {
                    return(true);
                }
                else
                {
                    throw new NotImplementedException(node.WhatIsThis()); // not resolved?
                }
            }
            else
            {
                // 3 or 4
                throw new NotImplementedException(node.AsText() + "   ## " + statement.WhatIsThis());
            }
        }
        public override void ExplicitVisit(ColumnReferenceExpression node)
        {
            string columnName;

            if (node.MultiPartIdentifier.Count == 1)
            {
                columnName = node.MultiPartIdentifier[0].Value;
            }
            else
            {
                throw new NotImplementedException(node.AsText());
            }

            cs.CodeExpression targetObject = new cs.CodeThisReferenceExpression();

            this.lastExpression = new cs.CodeFieldReferenceExpression(targetObject, columnName);
        }