ISqlHavingBuilder.HavingValue(string left, SqlBinaryOperator sqlOperator, object value) Method
.NET Standard 2.x
Creates a HAVING
clause, and adds a search condition to the HAVING
clause. You can specify the SQL expression on the left the operator and a specific value on the right of the operator.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
ISqlHavingAndOr HavingValue(string left, SqlBinaryOperator sqlOperator, object value);
Parameters
left
System.String
An expression on the left of the operator.
SqlBinaryOperator
SnapObjects.Data.SqlBinaryOperator
An enumeration value of SqlBinaryOperator
which is the operator to test the expression on the left and the value on the right.
value
System.Object
The specific value on the right of the operator.
Returns
SnapObjects.Data.ISqlHavingAndOr
Returns the ISqlHavingAndOr
object which can be used to add more search conditions to the current HAVING
clause.
Examples
The following code example demonstrates how to use the HavingValue method to specify the HAVING condition for groups.
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.ISqlHavingBuilderExamples
{
public class HavingValueExample
{
private readonly SchoolContext _context;
public HavingValueExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example2()
{
var sqlQueryBuilder = new SqlQueryBuilder();
// Groups "StudentGrade" table by StudentID and CourseID, and gets the sum of Grade of each group.
// Specifies the HAVING condition for group to: StudentID less than 10.
sqlQueryBuilder
.Select("StudentID")
.Select("sum(Grade)")
.From("StudentGrade")
.GroupBy("StudentID, CourseID")
.HavingValue("StudentID", SqlBinaryOperator.LessThan, 10);
// Converts to raw SQL for the database corresponding to the data context.
string sql = sqlQueryBuilder.ToSqlString(_context);
Console.WriteLine(sql);
/*This code example produces the following output:
SELECT
[StudentID],
sum(Grade)
FROM [StudentGrade]
GROUP BY
[StudentID],
[CourseID]
HAVING ([StudentID] < 10)
*/
}
}
}
Applies to
.NET Standard
2.x