Пример #1
0
        protected List <JoinQueryInfo> GetJoinInfos(ISqlBuilder sqlBuilder, Expression joinExpression, ref List <SugarParameter> parameters, ref string shortName, params Type[] entityTypeArray)
        {
            List <JoinQueryInfo> result          = new List <JoinQueryInfo>();
            var lambdaParameters                 = ((LambdaExpression)joinExpression).Parameters.ToList();
            ILambdaExpressions expressionContext = sqlBuilder.QueryBuilder.LambdaExpressions;

            expressionContext.MappingColumns = this.MappingColumns;
            expressionContext.MappingTables  = this.MappingTables;
            if (this.Context.CurrentConnectionConfig.MoreSettings != null)
            {
                expressionContext.PgSqlIsAutoToLower = this.Context.CurrentConnectionConfig.MoreSettings.PgSqlIsAutoToLower;
            }
            else
            {
                expressionContext.PgSqlIsAutoToLower = true;
            }
            if (this.Context.CurrentConnectionConfig.ConfigureExternalServices != null)
            {
                expressionContext.SqlFuncServices = this.Context.CurrentConnectionConfig.ConfigureExternalServices.SqlFuncServices;
            }
            expressionContext.Resolve(joinExpression, ResolveExpressType.Join);
            int i         = 0;
            var joinArray = MergeJoinArray(expressionContext.Result.GetResultArray());

            if (joinArray == null)
            {
                return(null);
            }
            parameters = expressionContext.Parameters;
            foreach (var entityType in entityTypeArray)
            {
                var           isFirst         = i == 0; ++i;
                JoinQueryInfo joinInfo        = new JoinQueryInfo();
                var           hasMappingTable = expressionContext.MappingTables.HasValue();
                MappingTable  mappingInfo     = null;
                if (hasMappingTable)
                {
                    mappingInfo        = expressionContext.MappingTables.FirstOrDefault(it => it.EntityName.Equals(entityType.Name, StringComparison.CurrentCultureIgnoreCase));
                    joinInfo.TableName = mappingInfo != null ? mappingInfo.DbTableName : entityType.Name;
                }
                else
                {
                    joinInfo.TableName = entityType.Name;
                }
                if (isFirst)
                {
                    var firstItem = lambdaParameters.First();
                    lambdaParameters.Remove(firstItem);
                    shortName = firstItem.Name;
                }
                var joinString = joinArray[i * 2 - 2];
                joinInfo.ShortName = lambdaParameters[i - 1].Name;
                joinInfo.JoinType  = (JoinType)Enum.Parse(typeof(JoinType), joinString);
                joinInfo.JoinWhere = joinArray[i * 2 - 1];
                joinInfo.JoinIndex = i;
                result.Add((joinInfo));
            }
            expressionContext.Clear();
            return(result);
        }
Пример #2
0
 public virtual string ToJoinString(JoinQueryInfo joinInfo)
 {
     return(string.Format(
                this.JoinTemplate,
                joinInfo.JoinType.ToString() + PubConst.Space,
                Builder.GetTranslationTableName(joinInfo.TableName) + PubConst.Space,
                joinInfo.ShortName + PubConst.Space + joinInfo.TableWithString,
                joinInfo.JoinWhere));
 }
Пример #3
0
 public virtual string ToJoinString(JoinQueryInfo joinInfo)
 {
     return(string.Format(
                this.JoinTemplate,
                joinInfo.JoinType.ToString() + UtilConstants.Space,
                Builder.GetTranslationTableName(joinInfo.TableName) + UtilConstants.Space,
                joinInfo.ShortName + UtilConstants.Space + (TableWithString == SqlWith.Null ? " " : TableWithString),
                joinInfo.JoinWhere));
 }
Пример #4
0
        public virtual string ToJoinString(JoinQueryInfo joinInfo)
        {
            var name = joinInfo.TableName;

            if (this.AsTables.Any())
            {
                if (this.Context.MappingTables != null && this.Context.MappingTables.Any(it => it.DbTableName == name))
                {
                    name = this.Context.MappingTables.First(it => it.DbTableName == name).EntityName;
                }
                if (this.AsTables.Any(it => it.Key == name))
                {
                    name = this.AsTables.First(it => it.Key == name).Value;
                }
            }
            return(string.Format(
                       this.JoinTemplate,
                       joinInfo.JoinType.ToString() + UtilConstants.Space,
                       Builder.GetTranslationTableName(name) + UtilConstants.Space,
                       joinInfo.ShortName + UtilConstants.Space + (TableWithString == SqlWith.Null ? " " : TableWithString),
                       joinInfo.JoinWhere));
        }