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, joinInfo.JoinWhere)); }
protected List <JoinQueryInfo> GetJoinInfos(ISqlBuilder sqlBuilder, Expression joinExpression, ref List <DbLiteParameter> 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.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); }