public virtual void Visiting(SqlCountFunction countFunction) { if (countFunction.SqlExpression != null) { sqlBuilder.Append("Count("); if (countFunction.Distinct) { sqlBuilder.Append("Distinct "); } countFunction.SqlExpression.Accept(this); sqlBuilder.Append(")"); } else { sqlBuilder.Append("Count(*)"); } }
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; }
public virtual void Visited(SqlCountFunction countFunction) { }