Show / Hide Table of Contents

    ISqlWhereAndOr<TBuilder>.AndWhere(string left, SqlBinaryOperator sqlOperator, ISqlParameter parameter) Method

    .NET Standard 2.x

    Adds the AND logical operator and a search condition to the WHERE clause; and specifies a SQL expression to the left of the operator and a SQL parameter to the right of the operator.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      TBuilder AndWhere(string left, SqlBinaryOperator sqlOperator, ISqlParameter parameter);
    

    Parameters

    left System.String

    A SQL expression on the left of the operator.

    SqlBinaryOperator SnapObjects.Data.SqlBinaryOperator

    An enumeration value of SqlBinaryOperator, which is the operator to test the two expressions on the left and right.

    parameter SnapObjects.Data.ISqlParameter

    An ISqlParameter object which represents a SQL parameter on the right of the operator.

    It can be created by calling the SqlBuilder.Parameter method.

    Returns

    TBuilder

    Returns the TBuilder object which can be used to add more search conditions to the current WHERE clause.

    Examples

    The following code example demonstrates how to use the AndWhere method to add an AND condition to the WHERE clause. In this example, the AND condition will have a dynamic value which is specified by an input parameter and use the greater than operator ">".

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlWhereAndOrExamples
    {
        public class AndWhereExample
        {
            private readonly SchoolContext _context;
    
            public AndWhereExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example2()
            {
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement and adds an AND condition to WHERE clause: DepartmentID > @deptid (a parameter).
                sqlbuilder.Select("Title")
                    .From("Course")
                    .Where("CourseID", SqlBinaryOperator.GreaterThan,
                            SqlBuilder.Parameter<int>("courid"))
                    .AndWhere("DepartmentID", SqlBinaryOperator.GreaterThan, 
                          SqlBuilder.Parameter<int>("deptid"));
    
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                /*This code produces the following output:
    
                SELECT
                [Title]
                FROM [Course]
                WHERE ([CourseID] > @courid
                AND [DepartmentID] > @deptid)
               */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon