Ejemplo n.º 1
0
        public List <TemplateJoin> ReadJoins(StoreQueryDefinition query, StoreSchema schema)
        {
            var result      = new List <TemplateJoin>();
            var rightTables = new HashSet <string>();

            foreach (var join in query.Joins)
            {
                var          leftTable  = query.Tables[join.LeftObjectAlias].TableName;
                var          rightTable = query.Tables[join.RightObjectAlias].TableName;
                TemplateJoin tj;

                if (rightTables.Contains(join.RightObjectAlias))
                {
                    // flip
                    tj = new TemplateJoin
                    {
                        LeftField       = join.RightField,
                        LeftObjectAlias = join.RightObjectAlias,
                        LeftObject      = rightTable,

                        RightField       = join.LeftField,
                        RightObjectAlias = join.LeftObjectAlias,
                        RightObject      = leftTable
                    };
                }
                else
                {
                    tj = new TemplateJoin
                    {
                        LeftField        = join.LeftField,
                        LeftObjectAlias  = join.LeftObjectAlias,
                        LeftObject       = leftTable,
                        RightField       = join.RightField,
                        RightObjectAlias = join.RightObjectAlias,
                        RightObject      = rightTable
                    };

                    rightTables.Add(join.RightObjectAlias);
                }

                result.Add(tj);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public TemplateJoin ReadFrom(StoreQueryDefinition query, StoreSchema schema)
        {
            TemplateJoin result;
            var          join = query.Joins.FirstOrDefault();

            if (join != null)
            {
                var table = query.Tables[join.LeftObjectAlias].TableName;
                result = new TemplateJoin {
                    LeftField = join.LeftField, LeftObjectAlias = join.LeftObjectAlias, LeftObject = table
                };
            }
            else
            {
                var table = query.Tables.Values.First();
                result = new TemplateJoin {
                    LeftObjectAlias = table.ObjectAlias, LeftObject = table.TableName
                };
            }

            return(result);
        }