Esempio n. 1
0
        public virtual SqlColumnAlias GetPropertyColumn(IPropertyMap propertyMap, object hash)
        {
            if (hash == null)
            {
                hash = propertyMap;
            }
            SqlTableAlias tbl = sqlEmitter.GetTableAlias(propertyMap.MustGetTableMap(), hash);

            IColumnMap columnMap = propertyMap.GetColumnMap();

            return(tbl.GetSqlColumnAlias(columnMap));
        }
Esempio n. 2
0
        public virtual void GetListPropertySubselectAndAlias(IPropertyMap propertyMap, object hash, Hashtable columns, ArrayList order, string propPath, string suggestion)
        {
            if (hash == null)
            {
                hash = propertyMap;
            }
            ITableMap     listTableMap   = propertyMap.MustGetTableMap();
            ITableMap     parentTableMap = propertyMap.ClassMap.MustGetTableMap();
            SqlTableAlias parentTable    = sqlEmitter.GetTableAlias(parentTableMap, hash);

            SqlSelectStatement subSelect = new SqlSelectStatement(parentTableMap.SourceMap);

            //Hmmm....can an alias be redefined in a subselect?
            //SqlTableAlias listTable = subSelect.GetSqlTableAlias(listTableMap, "cnt" + subSelect.GetNextTableAliasIndex());
            SqlTableAlias listTable = subSelect.GetSqlTableAlias(listTableMap, "cnt" + sqlEmitter.Select.GetNextTableAliasIndex());

            SqlCountFunction count = new SqlCountFunction();

            subSelect.SqlSelectClause.AddSqlAliasSelectListItem(count);

            subSelect.SqlFromClause.AddSqlAliasTableSource(listTable);

            foreach (IColumnMap fkIdColumnMap in propertyMap.GetAllIdColumnMaps())
            {
                IColumnMap idColumnMap = fkIdColumnMap.MustGetPrimaryKeyColumnMap();

                SqlColumnAlias     fkIdColumn = listTable.GetSqlColumnAlias(fkIdColumnMap);
                SqlColumnAlias     idColumn   = parentTable.GetSqlColumnAlias(idColumnMap);
                SqlSearchCondition search     = subSelect.SqlWhereClause.GetNextSqlSearchCondition();

                search.GetSqlComparePredicate(fkIdColumn, SqlCompareOperatorType.Equals, idColumn);
            }

            if (suggestion == "")
            {
                suggestion = propPath;
            }

            SqlAliasSelectListItem countAlias = this.sqlEmitter.Select.SqlSelectClause.AddSqlAliasSelectListItem(subSelect, suggestion);

            this.sqlEmitter.PropertyColumnMap[propPath] = countAlias.SqlExpressionAlias.Alias;
        }
Esempio n. 3
0
        private void JoinNonPrimary(IPropertyMap iPropertyMap)
        {
            foreach (IColumnMap idColumn in iPropertyMap.GetAllIdColumnMaps())
            {
                SqlTableAlias  thisTableAlias = this.sqlEmitter.Select.GetSqlTableAlias(idColumn.TableMap.Name);
                SqlColumnAlias thisColAlias   = thisTableAlias.GetSqlColumnAlias(idColumn.Name);

                SqlTableAlias  parentTableAlias = this.sqlEmitter.Select.GetSqlTableAlias(idColumn.PrimaryKeyTable);
                SqlColumnAlias parentColAlias   = parentTableAlias.GetSqlColumnAlias(idColumn.PrimaryKeyColumn);

                if (!joinedNonPrimaries.ContainsKey(thisColAlias))
                {
                    if (!(joinedNonPrimaries[thisColAlias] == parentColAlias))
                    {
                        SqlSearchCondition search = this.sqlEmitter.Select.SqlWhereClause.GetNextSqlSearchCondition();
                        search.GetSqlComparePredicate(parentColAlias, SqlCompareOperatorType.Equals, thisColAlias);

                        joinedNonPrimaries[thisColAlias] = parentColAlias;
                    }
                }
            }
        }