public Count ( string columnName ) : IFunctionOrFrom | ||
columnName | string | |
리턴 | IFunctionOrFrom |
public void SelectCountWithSqlCharacters() { var sqlBuilder = new SelectSqlBuilder(MsSqlCharacters.Instance, (string)null); var sqlQuery = sqlBuilder .Count("Id") .From(typeof(Customer)) .Where("CustomerStatusId").IsEqualTo(CustomerStatus.Active) .ToSqlQuery(); Assert.Equal("SELECT COUNT([Id]) AS Id FROM [Sales].[Customers] WHERE ([CustomerStatusId] = @p0)", sqlQuery.CommandText); Assert.Equal(1, sqlQuery.Arguments.Count); Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType); Assert.Equal(CustomerStatus.Active, sqlQuery.Arguments[0].Value); }
public void SelectCountWithOtherColumn() { var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "CustomerStatusId"); var sqlQuery = sqlBuilder .Count("Id") .From(typeof(Customer)) .GroupBy("CustomerStatusId") .ToSqlQuery(); Assert.Equal("SELECT CustomerStatusId,COUNT(Id) AS Id FROM Sales.Customers GROUP BY CustomerStatusId", sqlQuery.CommandText); Assert.Empty(sqlQuery.Arguments); }
public void SelectChainingMultipleFunctions() { var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Column1"); var sqlQuery = sqlBuilder .Count("Column2", "Col2") .Max("Column3", "Col3") .From("Table") .ToSqlQuery(); Assert.Equal("SELECT Column1,COUNT(Column2) AS Col2,MAX(Column3) AS Col3 FROM Table", sqlQuery.CommandText); Assert.Empty(sqlQuery.Arguments); }
public void SelectCountWithAlias() { var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, (string)null); var sqlQuery = sqlBuilder .Count("Id", columnAlias: "CustomerCount") .From(typeof(Customer)) .ToSqlQuery(); Assert.Equal("SELECT COUNT(Id) AS CustomerCount FROM Sales.Customers", sqlQuery.CommandText); Assert.Empty(sqlQuery.Arguments); }
public void CountThrowsArgumentExceptionForNullColumnAlias() { var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty); var exception = Assert.Throws<ArgumentException>( () => sqlBuilder.Count("Column", null)); Assert.Equal(ExceptionMessages.ArgumentNullOrEmpty.FormatWith("columnAlias"), exception.Message); }