本文整理汇总了C#中MicroLite.Builder.SelectSqlBuilder类的典型用法代码示例。如果您正苦于以下问题:C# SelectSqlBuilder类的具体用法?C# SelectSqlBuilder怎么用?C# SelectSqlBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SelectSqlBuilder类属于MicroLite.Builder命名空间,在下文中一共展示了SelectSqlBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AndWhereThrowsArgumentExceptionForNullPredicate
public void AndWhereThrowsArgumentExceptionForNullPredicate()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty);
var exception = Assert.Throws<ArgumentException>(
() => sqlBuilder.AndWhere(null, new object()));
Assert.Equal(ExceptionMessages.ArgumentNullOrEmpty.FormatWith("predicate"), exception.Message);
}
示例2: AverageThrowsArgumentExceptionForNullColumnAlias
public void AverageThrowsArgumentExceptionForNullColumnAlias()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty);
var exception = Assert.Throws<ArgumentException>(
() => sqlBuilder.Average("Column", null));
Assert.Equal(ExceptionMessages.ArgumentNullOrEmpty.FormatWith("columnAlias"), exception.Message);
}
示例3: AndWhereThrowsArgumentExceptionForEmptyColumn
public void AndWhereThrowsArgumentExceptionForEmptyColumn()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty);
var exception = Assert.Throws<ArgumentException>(
() => sqlBuilder.AndWhere(""));
Assert.Equal(ExceptionMessages.ArgumentNullOrEmpty.FormatWith("column"), exception.Message);
}
示例4: AndWhereThrowsArgumentNullExceptionForEmptyArgs
public void AndWhereThrowsArgumentNullExceptionForEmptyArgs()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty);
var exception = Assert.Throws<ArgumentNullException>(
() => sqlBuilder.AndWhere("x = ?", null));
Assert.Equal("args", exception.ParamName);
}
示例5: SelectDistinctColumnWithSqlCharacters
public void SelectDistinctColumnWithSqlCharacters()
{
var sqlBuilder = new SelectSqlBuilder(MsSqlCharacters.Instance, (string)null);
var sqlQuery = sqlBuilder
.Distinct("CreditLimit")
.From(typeof(Customer))
.ToSqlQuery();
Assert.Equal("SELECT DISTINCT [CreditLimit] FROM [Sales].[Customers]", sqlQuery.CommandText);
Assert.Equal(0, sqlQuery.Arguments.Count);
}
示例6: SelectDistinctColumn
public void SelectDistinctColumn()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, (string)null);
var sqlQuery = sqlBuilder
.Distinct("CreditLimit")
.From(typeof(Customer))
.ToSqlQuery();
Assert.Equal("SELECT DISTINCT CreditLimit FROM Sales.Customers", sqlQuery.CommandText);
Assert.Equal(0, sqlQuery.Arguments.Count);
}
示例7: SelectFromWhereOr
public void SelectFromWhereOr()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Column1", "Column2");
var sqlQuery = sqlBuilder
.From("Table")
.Where("Column1").IsEqualTo("Foo")
.OrWhere("Column2").IsEqualTo("Bar")
.ToSqlQuery();
Assert.Equal("SELECT Column1,Column2 FROM Table WHERE (Column1 = ?) OR (Column2 = ?)", sqlQuery.CommandText);
Assert.Equal(2, sqlQuery.Arguments.Count);
Assert.Equal(DbType.String, sqlQuery.Arguments[0].DbType);
Assert.Equal("Foo", sqlQuery.Arguments[0].Value);
Assert.Equal(DbType.String, sqlQuery.Arguments[1].DbType);
Assert.Equal("Bar", sqlQuery.Arguments[1].Value);
}
示例8: NotBetweenThrowsArgumentExceptionForNullUpper
public void NotBetweenThrowsArgumentExceptionForNullUpper()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty);
var exception = Assert.Throws<ArgumentNullException>(
() => sqlBuilder.NotBetween(1, null));
Assert.Equal("upper", exception.ParamName);
}
示例9: SelectFromSpecifyingColumnsAndTableNameWithSqlCharacters
public void SelectFromSpecifyingColumnsAndTableNameWithSqlCharacters()
{
var sqlBuilder = new SelectSqlBuilder(MsSqlCharacters.Instance, "Column1", "Column2");
var sqlQuery = sqlBuilder
.From("Table")
.ToSqlQuery();
Assert.Equal("SELECT [Column1],[Column2] FROM [Table]", sqlQuery.CommandText);
Assert.Empty(sqlQuery.Arguments);
}
示例10: SelectFromOrderByDescendingWithSqlCharacters
public void SelectFromOrderByDescendingWithSqlCharacters()
{
var sqlBuilder = new SelectSqlBuilder(MsSqlCharacters.Instance, "Column1", "Column2");
var sqlQuery = sqlBuilder
.From("Table")
.OrderByDescending("Column1", "Column2")
.ToSqlQuery();
Assert.Equal("SELECT [Column1],[Column2] FROM [Table] ORDER BY [Column1] DESC,[Column2] DESC", sqlQuery.CommandText);
Assert.Empty(sqlQuery.Arguments);
}
示例11: SelectAverageWithOtherColumn
public void SelectAverageWithOtherColumn()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "Id");
var sqlQuery = sqlBuilder
.Average("CreditLimit")
.From(typeof(Customer))
.Where("CustomerStatusId").IsEqualTo(CustomerStatus.Active)
.GroupBy("CustomerStatusId")
.ToSqlQuery();
Assert.Equal("SELECT Id,AVG(CreditLimit) AS CreditLimit FROM Sales.Customers WHERE (CustomerStatusId = ?) GROUP BY CustomerStatusId", sqlQuery.CommandText);
Assert.Equal(1, sqlQuery.Arguments.Count);
Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType);
Assert.Equal(CustomerStatus.Active, sqlQuery.Arguments[0].Value);
}
示例12: SelectAverageWithAlias
public void SelectAverageWithAlias()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, (string)null);
var sqlQuery = sqlBuilder
.Average("CreditLimit", columnAlias: "AverageCreditLimit")
.From(typeof(Customer))
.Where("CustomerStatusId").IsEqualTo(CustomerStatus.Active)
.ToSqlQuery();
Assert.Equal("SELECT AVG(CreditLimit) AS AverageCreditLimit FROM Sales.Customers WHERE (CustomerStatusId = ?)", sqlQuery.CommandText);
Assert.Equal(1, sqlQuery.Arguments.Count);
Assert.Equal(DbType.Int32, sqlQuery.Arguments[0].DbType);
Assert.Equal(CustomerStatus.Active, sqlQuery.Arguments[0].Value);
}
示例13: OrderByDescendingThrowsArgumentNullException
public void OrderByDescendingThrowsArgumentNullException()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "CustomerId");
Assert.Throws<ArgumentException>(
() => sqlBuilder.From("Customer").OrderByDescending((string)null));
Assert.Throws<ArgumentException>(
() => sqlBuilder.From("Customer").OrderByDescending(string.Empty));
Assert.Throws<ArgumentNullException>(
() => sqlBuilder.From("Customer").OrderByDescending((string[])null));
}
示例14: OrderByDescendingAppendsColumnsCorrectlyForSingleColumn
public void OrderByDescendingAppendsColumnsCorrectlyForSingleColumn()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "CustomerId");
var sqlQuery = sqlBuilder.From("Customer")
.OrderByDescending("CustomerId")
.ToSqlQuery();
Assert.Equal("SELECT CustomerId FROM Customer ORDER BY CustomerId DESC", sqlQuery.CommandText);
}
示例15: OrderByAscendingAppendsColumnsCorrectlyForMultipleColumns
public void OrderByAscendingAppendsColumnsCorrectlyForMultipleColumns()
{
var sqlBuilder = new SelectSqlBuilder(SqlCharacters.Empty, "CustomerId");
var sqlQuery = sqlBuilder.From("Customer")
.OrderByAscending("FirstName", "LastName")
.ToSqlQuery();
Assert.Equal("SELECT CustomerId FROM Customer ORDER BY FirstName ASC,LastName ASC", sqlQuery.CommandText);
}