コード例 #1
0
        public SqlQueryBuilder From(string alias, string tableName)
        {
            tableName.AssertHasText(nameof(tableName));
            alias.AssertHasText(nameof(alias));


            TableItem fromTable = new TableItem(TableRole.FromTable, alias, tableName);

            _tablesMap.AddIfNecessary(fromTable);
            _query.Append($"SELECT {_selectFields.Select(x => x.ToString()).StringJoin(",")}");
            _query.Append($" FROM {tableName} {alias}");
            _joinInfo = new JoinInfo(fromTable);

            return(this);
        }
コード例 #2
0
        private string JoinClause(JoinType type, string tableAlias, string tableName)
        {
            tableAlias.AssertHasText(nameof(tableAlias));
            tableName.AssertHasText(nameof(tableName));

            string    joinClause = null;
            TableRole role       = TableRole.FromTable;

            switch (type)
            {
            case JoinType.CrossJoin:
                joinClause = $" CROSS JOIN {tableName} {tableAlias}";
                role       = TableRole.CrossJoinTable;
                break;

            case JoinType.FullJoin:
                joinClause = $" FULL JOIN {tableName} {tableAlias}";
                role       = TableRole.FullJoinTable;
                break;

            case JoinType.InnerJoin:
                joinClause = $" INNER JOIN {tableName} {tableAlias}";
                role       = TableRole.InnerJoinTable;
                break;

            case JoinType.LeftJoin:
                joinClause = $" LEFT JOIN {tableName} {tableAlias}";
                role       = TableRole.LeftJoinTable;
                break;

            case JoinType.RightJoin:
                joinClause = $" RIGHT JOIN {tableName} {tableAlias}";
                role       = TableRole.RightJoinTable;
                break;
            }

            TableItem tableItem = new TableItem(role, tableAlias, tableName);

            _joinInfo.RightTable = tableItem;
            _tablesMap.AddIfNecessary(tableItem);

            return(joinClause);
        }
コード例 #3
0
 public JoinInfo(TableItem leftTable)
 {
     leftTable.AssertNotNull(nameof(leftTable));
     LeftTable = leftTable;
 }