Пример #1
0
        protected virtual IList <string> GetAllAliases(TranslationContext context)
        {
            var aliases = new List <string>();

            aliases.AddRange(context.EnumerateAllTables().Select(t => t.Alias));
            aliases.AddRange(context.EnumerateScopeColumns().Select(c => c.Alias));
            return(aliases);
        }
Пример #2
0
        /// <summary>
        /// Give all non-aliased tables a name
        /// </summary>
        /// <param name="context"></param>
        protected virtual void CheckTablesAlias(TranslationContext context)
        {
            var tables = context.EnumerateAllTables().Distinct().ToList();

            // just to be nice: if we have only one table involved, there's no need to alias it
            if (tables.Count == 1)
            {
                tables[0].Alias = null;
            }
            else
            {
                var allAliases = GetAllAliases(context);
                foreach (var tableExpression in tables)
                {
                    // if no alias, or duplicate alias
                    if (string.IsNullOrEmpty(tableExpression.Alias) || allAliases.Count(s => s == tableExpression.Alias) > 1)
                    {
                        tableExpression.Alias = GenerateTableAlias(allAliases);
                    }
                }
            }
        }
Пример #3
0
 protected virtual IList<string> GetAllAliases(TranslationContext context)
 {
     var aliases = new List<string>();
     aliases.AddRange(context.EnumerateAllTables().Select(t => t.Alias));
     aliases.AddRange(context.EnumerateScopeColumns().Select(c => c.Alias));
     return aliases;
 }
 private Expression AnalyzeJoin(IList<Expression> parameters, TableJoinType joinType, TranslationContext context)
 {
     if (parameters.Count == 5)
     {
         var outerExpr = Analyze(parameters[0], context);
         var innerExpr = Analyze(parameters[1], context);
         var innerTable = innerExpr as TableExpression;
         // TODO: fix this. When joined table is a subquery, we have this exception
         if (innerTable == null)
            Util.Throw("Join with sub-query is not supported. Sub-query: {0}.", innerExpr);
         // RI: check if key selectors return Entity: if yes, change to PK
         var outerSel = CheckJoinKeySelector(parameters[2], context);
         var innerSel = CheckJoinKeySelector(parameters[3], context);
         var outerKeySelector = Analyze(outerSel, outerExpr, context);
         var innerKeySelector = Analyze(innerSel, innerTable, context);
         // from here, we have two options to join:
         // 1. left and right are tables, we can use generic expressions (most common)
         // 2. left is something else (a meta table)
         var outerTable = outerExpr as TableExpression;
         if (outerTable == null)
         {
             var outerKeyColumn = outerKeySelector as ColumnExpression;
             if (outerKeyColumn == null)
                 Util.Throw("S0701: No way to find left table for Join");
             outerTable = outerKeyColumn.Table;
         }
         var joinExpr = ExpressionUtil.MakeBinary(ExpressionType.Equal, outerKeySelector, innerKeySelector);
         innerTable.Join(joinType, outerTable, joinExpr,
                         string.Format("join{0}", context.EnumerateAllTables().Count()));
         // last part is lambda, with two tables as parameters
         var metaTableDefinitionBuilderContext = new TranslationContext(context);
         //metaTableDefinitionBuilderContext.ExpectMetaTableDefinition = true;
         var expression = Analyze(parameters[4], new[] { outerExpr, innerTable }, metaTableDefinitionBuilderContext);
         return expression;
     }
     Util.Throw("S0530: Don't know how to handle GroupJoin() with {0} parameters", parameters.Count);
     return null;
 }
Пример #5
0
 /// <summary>
 /// Give all non-aliased tables a name
 /// </summary>
 /// <param name="context"></param>
 protected virtual void CheckTablesAlias(TranslationContext context)
 {
     var tables = context.EnumerateAllTables().Distinct().ToList();
     // just to be nice: if we have only one table involved, there's no need to alias it
     if (tables.Count == 1)
     {
       tables[0].Alias = null;
     } else {
       var allAliases = GetAllAliases(context);
       foreach (var tableExpression in tables)
       {
             // if no alias, or duplicate alias
             if (string.IsNullOrEmpty(tableExpression.Alias) || allAliases.Count(s => s == tableExpression.Alias) > 1)
               tableExpression.Alias = GenerateTableAlias(allAliases);
         }
     }
 }