private void VisitJoinSelector(Expression joinSelector, string outerTypeName, string innerTypeName, FetchLinkEntity link)
        {
            UnaryExpression uexp = joinSelector as UnaryExpression;
            LambdaExpression lxp = (uexp.Operand as LambdaExpression);
            NewExpression nxp = lxp.Body as NewExpression;

            //if(nxp.Arguments[0].NodeType == ExpressionType.
            foreach (Expression exp in nxp.Arguments)
            {
                string entName;
                // the format of the selector depends on the presence of a where clause it seems
                if (exp is MemberExpression)
                {
                    MemberExpression masgn = exp as MemberExpression;
                    entName = (masgn.Expression as ParameterExpression).Type.Name;
                    if (entName == outerTypeName) // add to outer attributes
                        stmt.Entity.Columns.Columns.Add(masgn.Member.Name);
                    else if (entName == innerTypeName) // add to link-entity columns
                        link.Columns.Columns.Add(masgn.Member.Name);

                }
                else if (exp is ParameterExpression)
                {
                    ParameterExpression pExp = exp as ParameterExpression;
                    entName = pExp.Type.Name;
                    if (entName == innerTypeName)
                        // record the alias and link-node for future use
                        attributeMap.Add(pExp.Name, link);
                    //if(entName == outerTypeName)
                    // do nothing, this will be handled by the regular selector

                }
                else
                {
                    throw new Exception("Unknown Expression type when visiting join-selector");
                }

            }
        }
        private void VisitJoin(MethodCallExpression join)
        {
            // this will set up the correct Fetchentity
            this.Visit(join.Arguments[0]);
            FetchLinkEntity link;
            // TODO: Handle non-dotted values
            MemberExpression outerMemberExp = (((join.Arguments[2] as UnaryExpression).Operand as LambdaExpression).Body as MemberExpression).Expression as MemberExpression;
            MemberExpression innerMemberExp = (((join.Arguments[3] as UnaryExpression).Operand as LambdaExpression).Body as MemberExpression).Expression as MemberExpression;
            string outerTypeName = outerMemberExp.Expression.Type.Name;
            string innerTypeName = innerMemberExp.Expression.Type.Name;

            // This was commented out to allow intra-table joins - wonder why I put it in?
            //if (!innerTypeName.Equals(stmt.Entity.EntityName))
            //{
            link = new FetchLinkEntity(innerTypeName);
            link.From = innerMemberExp.Member.Name;
            link.To = outerMemberExp.Member.Name;
            //}
            //else
            //    throw new ArgumentException();
            link.Columns = new FetchColumnSet();
            link.Columns.Columns = new System.Collections.Specialized.StringCollection();
            // TODO: this is very bad karma, but I'm too tired now
            link.Alias = "";
            stmt.Entity.LinkEntities.Add(link);

            // now get the attributes
            VisitJoinSelector(join.Arguments[4], outerTypeName, innerTypeName, link);

        }