Пример #1
0
        protected virtual SqlExpression <T> InternalJoin(string joinType, Expression joinExpr, ModelDefinition sourceDef, ModelDefinition targetDef, TableOptions options = null)
        {
            PrefixFieldWithTableName = true;

            Reset();

            var joinFormat = options?.JoinFormat;

            if (options?.Alias != null) //Set joinAlias
            {
                options.ParamName = joinExpr is LambdaExpression l && l.Parameters.Count == 2
                    ? l.Parameters[1].Name
                    : null;
                if (options.ParamName != null)
                {
                    joinFormat       = null;
                    options.ModelDef = targetDef;
                    joinAlias        = options;
                }
            }


            if (!tableDefs.Contains(sourceDef))
            {
                tableDefs.Add(sourceDef);
            }
            if (!tableDefs.Contains(targetDef))
            {
                tableDefs.Add(targetDef);
            }

            var isCrossJoin = "CROSS JOIN" == joinType;

            var sqlExpr = joinExpr != null
                ? InternalCreateSqlFromExpression(joinExpr, isCrossJoin)
                : InternalCreateSqlFromDefinitions(sourceDef, targetDef, isCrossJoin);

            var joinDef = tableDefs.Contains(targetDef) && !tableDefs.Contains(sourceDef)
                ? sourceDef
                : targetDef;

            FromExpression += joinFormat != null
                ? $" {joinType} {joinFormat(DialectProvider, joinDef, sqlExpr)}"
                : joinAlias != null
                    ? $" {joinType} {SqlTable(joinDef)} AS {DialectProvider.GetQuotedName(joinAlias.Alias)} {sqlExpr}"
                    : $" {joinType} {SqlTable(joinDef)} {sqlExpr}";


            if (joinAlias != null) //Unset joinAlias
            {
                joinAlias = null;
                if (options != null)
                {
                    options.ParamName = null;
                    options.ModelDef  = null;
                }
            }

            return(this);
        }
Пример #2
0
        public override string ToString()
        {
            var text = SelectExpression;

            if (!string.IsNullOrEmpty(Alias)) // Note that even though Alias must be non-empty in the constructor it may be set to null/empty later
            {
                text += " AS " + DialectProvider.GetQuotedName(Alias);
            }
            return(text);
        }
Пример #3
0
        public override string ToString()
        {
            var text = DialectProvider.GetQuotedColumnName(ColumnName);

            if (!string.IsNullOrEmpty(QuotedTableAlias))
            {
                text = QuotedTableAlias + "." + text;
            }
            if (!string.IsNullOrEmpty(Alias))
            {
                text += " AS " + DialectProvider.GetQuotedName(Alias);
            }

            return(text);
        }